raman Posted October 29, 2009 Share Posted October 29, 2009 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 More sharing options...
raman Posted October 29, 2009 Author Share Posted October 29, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.