Jump to content

Archived

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

Nhoj

How do you insert a string into another string?

Recommended Posts

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>&nbsp;</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.

Share this post


Link to post
Share on other sites
[!--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>&nbsp;</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]

Share this post


Link to post
Share on other sites
[!--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>&nbsp;</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.

Share this post


Link to post
Share on other sites
[!--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\" /]

Share this post


Link to post
Share on other sites

×

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.