string - Adding characters to str_replace in PHP -


i have php file thread ($tid) , post ($pid) ids defined , i'm looking use str_replace combine them , create desired output (below) &p= added:

desired output:

$tid&p=$pid 

the closest i've got doing this:

$tid=$t1; $pid=$p1; $tid=str_replace("$tid","$tid"."$pid",$tid); 

the result is:

$tid$pid 

i may need use function (not sure if so?) in str_replace support &p= being added, trying add in quotes directly doesn't seem work resulting in database errors.

edit #1: tried doing following based on comments far:

$tid=""; $tid.="$t1"; $tid.="$p1";  $tid=$tid; 

that results in same previous example above:

$tid$pid 

as add &p= database error:

$tid.="&p="; 

so question how add &p= edit #1 example above correctly?

i'm attempting understand question little bit. have couple options alluded in comments above. could, instance (where '1', '2', , '3' replaced desired values):

<?php $tid=1; $pid=2; $amp=3; $tid=str_replace("$tid","$tid".'$amp;p='."$pid",$tid);  echo $tid; ?> 

here can explicitly state in 'replace' argument of str_replace missing string should part of replacement string.

or use concatenation operator generate string desire simpler given (little) know of surrounding code/use-case:

<?php $tid=1; $pid=2; $amp=3;  echo "$tid".'$amp;p='."$pid"; ?> 

the reason i'd recommend latter, due fact it's less resource intensive produce desired result appears string. str_replace() searches "haystack" or subject string using search string , must replace each of found instances replace string.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -