Nhoj Posted June 22, 2006 Share Posted June 22, 2006 I'm not exactly what I would call new to the coding field, but this is just stumping the life out of me, so if anyone can help i'd appreciate it.What I want to do is take a large block of text and html tags such as:[code]Equip: <a href="BLAH BLAH LINK" class="itemeffectlink">This is just a big giant bunch of mumbo jumbo</a> </span><br/><br/><a href="./set.php?tid=207">[/code]And change the last part:[code]<a href="./set.php?id=207">[/code]to[code]<a href="./set.php?id=207" class='goldtext'>[/code]But when I do this, I need the number 207 to be a number that can change, also the original text needs to be able to change also.Basically all i'm doing is inserting the class goldtext to the link tag.If you can understand my rambling and don't mind helping, please do. Quote Link to comment https://forums.phpfreaks.com/topic/12627-how-do-you-insert-a-string-into-another-string/ Share on other sites More sharing options...
AndyB Posted June 22, 2006 Share Posted June 22, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Basically all i'm doing is inserting the class goldtext to the link tag[/quote]Use the str_replace function similarly to the code below:[code]<?php$mytext = 'Equip: <a href="BLAH BLAH LINK" class="itemeffectlink">This is just a big giant bunch of mumbo jumbo</a> </span><br/><br/><a href="./set.php?tid=207">';$mytext_new = str_replace('<a href="./set', '<a class="goldtest" href="./set',$mytext);echo $mytext_new;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12627-how-do-you-insert-a-string-into-another-string/#findComment-48432 Share on other sites More sharing options...
Nhoj Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386802:date=Jun 22 2006, 06:30 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 22 2006, 06:30 AM) [snapback]386802[/snapback][/div][div class=\'quotemain\'][!--quotec--]Use the str_replace function similarly to the code below:[code]<?php$mytext = 'Equip: <a href="BLAH BLAH LINK" class="itemeffectlink">This is just a big giant bunch of mumbo jumbo</a> </span><br/><br/><a href="./set.php?tid=207">';$mytext_new = str_replace('<a href="./set', '<a class="goldtest" href="./set',$mytext);echo $mytext_new;?>[/code][/quote]Well that was extremely simple, I had been attempting a complicated array of preg_match and preg_replace.Now I have another problem, any idea on how I would remove[code]<span class="goldtext"></span>[/code]From something like[code]<span class="goldtext">Test Text</span>[/code]I can easily do the str_replace to remove the front part, but if I did that for the </span> it would remove multiple </span> parts of the original text. Quote Link to comment https://forums.phpfreaks.com/topic/12627-how-do-you-insert-a-string-into-another-string/#findComment-48433 Share on other sites More sharing options...
Nhoj Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386803:date=Jun 22 2006, 06:33 AM:name=JohnO.)--][div class=\'quotetop\']QUOTE(JohnO. @ Jun 22 2006, 06:33 AM) [snapback]386803[/snapback][/div][div class=\'quotemain\'][!--quotec--]Well that was extremely simple, I had been attempting a complicated array of preg_match and preg_replace.Now I have another problem, any idea on how I would remove[code]<span class="goldtext"></span>[/code]From something like[code]<span class="goldtext">Test Text</span>[/code]I can easily do the str_replace to remove the front part, but if I did that for the </span> it would remove multiple </span> parts of the original text.[/quote]nvm I got it by using a preg_replace statement, ty for all your help [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12627-how-do-you-insert-a-string-into-another-string/#findComment-48434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.