Jump to content

Recommended Posts

Hi all,

 

i have string

<div align="center"> 
                <p><a class=lns 
                              href="../index-2.html">etourism </a>|<a class=lns 
                              href="places.html"> Destination</a> | <a class=lns 
                              href="restaurant.html">Restaurant</a> |<a class=lns 
                              href="travel.html"> Travel-agent</a> | <a class=lns 
                              href="money.html">Money-changer </a> |<a class=lns 
                              href="shop.html"> Artshop</a> | <a class=lns 
                              href="history.html">History</a> | <a class=lns 
                              href="map/index.html">Map</a><br>

                  <A class=lns 
                              href="../general/say.html">Say in Indonesia</A> 
                  | <A class=lns 
                              href="../general/dont.html">Do & Don'ts </A>|<A class=lns 
                              href="../general/health.html"> Tropical Health </A> 
                  | <A class=lns 
                              href="../general/essntl.html">Essential</A> |<A class=lns 
                              href="../general/fact.html"> Fast-fact</A> | <A class=lns 
                              href="../general/formal.html">Travel Formality</A> 
                  | <A class=lns 
                              href="mailto:webmaster@etourism.com">Webmaster</A> 
                  |<A class=lns 
                              href="../general/term.html"> Term of Use</A> </p>

              </div>
            </div>

 

how to remove using preg_replace only for link and anchor text

<A class=lns 
                              href="mailto:webmaster@etourism.com">Webmaster</A> 
                  |

 

I'm using preg_replace('/<A class=lns(.*)webmaster@etourism.com(.*)\|/i','',$str);

but not work

Link to comment
https://forums.phpfreaks.com/topic/189622-replace-link/
Share on other sites

Your problem is your stars are greedy.  change .* to .*?  though personally I'd probably suggest using a negative char class instead:  [^|]*

 

Also since you are replacing it with nothing, no reason to capture anything in there (get rid of the parenthesis)

 

Also judging by your example, you may need to add the s modifier to your pattern.

                           

Link to comment
https://forums.phpfreaks.com/topic/189622-replace-link/#findComment-1000898
Share on other sites

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.