Jump to content

replacements


raman

Recommended Posts

I have a variable in my PHP script like

 

ASSFDDDDDDDDDDDDDASDDDDDDDDARYTRHKKHHHHHHHHHHH and positions 5-10

 

I want to replace these positions with another color .

 

$newpat="<font color=blue>$pat</font>";

 

can someone tell me what function to use and how, I tried string_replace, but didn't work. I did not know hoe I could tell it to replace specific positions and multiple at a time.

Link to comment
https://forums.phpfreaks.com/topic/179457-replacements/
Share on other sites

 

I am using this code, but aprt from replacing at the positions, it is also replacing the same item if it occurs at some other position.

Here $loww is the starting position, say 5 and $upp is the final position of replacement, that is 10. If I wanted to replace AAAAAA from 5-10, it is replacing A with bue color A but it is also doing it for other posiitions.

 

 



$pdb=explode("-",$posn);
$loww=$pdb[0];
$upp=$pdb[1];



for($i=$loww-1;$i<$upp-1;$i++){
  $aw="<font color=blue>$seq[$i]</font>";
  echo "*****$aw";
  $repseq=str_replace("$seq[$i]","$aw",$seq);
}

 

Link to comment
https://forums.phpfreaks.com/topic/179457-replacements/#findComment-946850
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.