Jump to content

Replace link


sastro

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:[email protected]">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:[email protected]">Webmaster</A> 
                  |

 

I'm using preg_replace('/<A class=lns(.*)[email protected](.*)\|/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

Archived

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

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