Jump to content

[SOLVED] preg_replace!


b00ker_b0y

Recommended Posts

hey people, trying to  use preg_replace to edit some text. For example, the following text has links and an image.

 

I want the normal links to stay, and the breaks "< b r >" but i want the image and it link at the end to be removed. What ever i am doing is causing issues like messing up links of removing the breaks so i am doign something wrong.

 

 

Spain had also regained its growth in the overall number of <a href="http://www.lamangaspain.com/index.htm" target="_blank">holidays</a> from the UK, after being hit by the rise in popularity of other cheap destinations such as Egypt, Turkey and Eastern Europe.<br/><br/>In total, Brits made over 12 million trips to Spain last year to spend more than &#163;5 billion on their southern neighbours.<br/><br/>According to Mintel, agents were currently struggling in Spain, and needed to expand or appeal to a more high-end market to reverse the negative trend.<br/><br/>The research showed that the country's appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.<br/><img alt="ADNFCR-1179-ID-18240457-ADNFCR" src="http://feeds.directnews.co.uk/feedtrack/adferocopyright.gif?feedid=1179&itemid=18240457" />

 

Any ideas truely are weclomed. Thanks people.

Link to comment
Share on other sites

hey, sorry did not know where to post this?

thought i was in correct place.

 

$logo_description = $news[Content];
		$logoless_description = preg_replace("/<img/", "", $logo_description);
		$logoless_description = preg_replace(" />/", "", $logo_description);

 

just want the text be the same with all the breaks, and links in tact, just with the image and its link on the end removed.

Link to comment
Share on other sites

OK but this foum has parsed the post so i have no idea what you want?

 

can you post and example ie

 

from

The research showed that the country's appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.
<img src="test.jpg">

 

 

to

The research showed that the country's appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.

Link to comment
Share on other sites

From:

Spain had also regained its growth in the overall number of <a href="http://www.lamangaspain.com/index.htm" target="_blank">holidays</a> from the UK, after being hit by the rise in popularity of other cheap destinations such as Egypt, Turkey and Eastern Europe.<br/><br/>In total, Brits made over 12 million trips to Spain last year to spend more than &#163;5 billion on their southern neighbours.<br/><br/>According to Mintel, agents were currently struggling in Spain, and needed to expand or appeal to a more high-end market to reverse the negative trend.<br/><br/>The research showed that the country's appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.<br/><img alt="ADNFCR-1179-ID-18240457-ADNFCR" src="http://feeds.directnews.co.uk/feedtrack/adferocopyright.gif?feedid=1179&itemid=18240457" />

 

To:

Spain had also regained its growth in the overall number of <a href="http://www.lamangaspain.com/index.htm" target="_blank">holidays</a> from the UK, after being hit by the rise in popularity of other cheap destinations such as Egypt, Turkey and Eastern Europe.<br/><br/>In total, Brits made over 12 million trips to Spain last year to spend more than &#163;5 billion on their southern neighbours.<br/><br/>According to Mintel, agents were currently struggling in Spain, and needed to expand or appeal to a more high-end market to reverse the negative trend.<br/><br/>The research showed that the country's appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.<br/>

 

just want image knocked off the end, but the image could be different so have a different name so just need remove everthing between <img and />.

 

<img alt="ADNFCR-1179-ID-18240457-ADNFCR" src="http://feeds.directnews.co.uk/feedtrack/adferocopyright.gif?feedid=1179&itemid=18240457" />

Link to comment
Share on other sites

so this i think

 

$data = 'Spain had also regained its growth in the overall number of <a href="http://www.lamangaspain.com/index.htm" target="_blank">holidays</a> from the UK, after being hit by the rise in popularity of other cheap destinations such as Egypt, Turkey and Eastern Europe.<br/><br/>In total, Brits made over 12 million trips to Spain last year to spend more than &#163;5 billion on their southern neighbours.<br/><br/>According to Mintel, agents were currently struggling in Spain, and needed to expand or appeal to a more high-end market to reverse the negative trend.<br/><br/>The research showed that the country\'s appeal to the young was falling as the 20 to 24 year old group was now the least likely to travel to the country.<br/><img alt="ADNFCR-1179-ID-18240457-ADNFCR" src="http://feeds.directnews.co.uk/feedtrack/adferocopyright.gif?feedid=1179&itemid=18240457" />';


$data = preg_replace('/(<img.*>)$/i', '', $data);

echo $data;

 

 

EDIT: escaped the ' ;P

Link to comment
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.