php - how to do multiple sub string replace at same time -
i want multiple sub string replace based on starting , length. have array values
(user-id,replace-name,starting,length) string: "hi rameez plz call charlie" sample array : array('123','rameez rami',4,6), array('124','charlie russet',20,7) and want is
my current code
$linkaddeddescription=input::get('description'); foreach ($descriptionmaparray $key=> $taggeditem) { //print_r($taggeditem);die; $tagwordstarting=$taggeditem[0]; $tagwordlength=$taggeditem[1]; $taggeditemdata=$taggeditem[3]; $descriptiontaglink='<a href="'.url::to("/").'/user/profile/'.$taggeditemdata->id.'">'.$taggeditemdata->name.'</a>'; $linkaddeddescription=substr_replace($linkaddeddescription,$descriptiontaglink,$tagwordstarting,$tagwordlength); //break; } print_r($linkaddeddescription);die;
i hope understanding question correctly. if so: have string ready spots want fill in in curly braces:
$outputstring = 'hi {name} plz call {othername}'; $firstperson = array('123', 'rameez', 4, 6); $secondperson = array('132', 'charlie', 3, 8); then use str_replace fill them data:
$outputstring = str_replace('{name}', $firstperson[1]); $outputstring = str_replace('{othername}', $secondperson[1]); (the string/arrays example of course, depends on data/wishes)
Comments
Post a Comment