Jump to content

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.
[!--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]
[!--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.
[!--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\" /]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.