Jump to content

Recommended Posts

I have a string

 

<p>Bollywood romcom: a pair of wouldbe suicides choose the same bridge at the same time.</p><p><a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a> (<a href="http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66" target="_blank">www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66</a>), Ozone Leisure Park, Grenoble Road (next Kassam Stadium), Oxford OX4 4XP; Tel. 08712 240 240 (10p per min from BT).<br /> </p>

 

Using php i want to extract

 

http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66

 

from the <a> tag.

 

I have already tried using

 

    
<?php

$pattern = "/<a href=\"([^\"]*)\">(.*)<\/a>/iU";
preg_match_all($pattern, $link, $matches);
var_dump($matches);
?> 

 

The output I get is

 

array

  0 =>

    array

      0 => string '<a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a>' (length=81)

  1 =>

    array

      0 => string 'http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema' (length=56)

  2 =>

    array

      0 => string 'Vue Cinema' (length=10)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/215060-need-help-extracting-data-from-string/
Share on other sites

Try this... its will probably only work in this string or string very similar...

<?
$string = '<p>Bollywood romcom: a pair of wouldbe suicides choose the same bridge at the same time.</p><p><a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a> (<a href="http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66" target="_blank">www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66</a>), Ozone Leisure Park, Grenoble Road (next Kassam Stadium), Oxford OX4 4XP; Tel. 08712 240 240 (10p per min from BT).<br /> </p>';

$string = explode('<a href="',$string);
$string = explode('" target',$string[2]);

echo $string[0];
?>

 

Tell me how it goes, also if you are wanting to do multi strings you should use preg_replace

 

Regards, Paul.

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.