Jump to content

regEx and simple_html_dom to extract a visible text in an anchor tag


kevinkhan

Recommended Posts

I want to extract the name within the anchor tag of the following code takin from a source file.

 

Has worked at <a href="http://www.facebook.com/pages/Bridewell-bar/110926698934250" data-hovercard="/ajax/hovercard/page.php?id=110926698934250">Bridewell bar</a>

 

is there anyway i can remove all the code before "Has worked at" and use the code below to extract the name

 

$page is full source code of page

 


include('simple_html_dom.php');

code to remove every thing before "Has worked at"

$job = str_get_html($page);
$job = $jobd->find(' next <a> tag',0);
$job = $job->value;

 

Any ideas and can somebody help me write the code.

 

iv tryed using strpos function but can figure it out :(

Hi,

Try use this example:

$str = 'SOme contennt - Has worked at <a href="http://www.facebook.com/pages/Bridewell-bar/110926698934250" data-hovercard="/ajax/hovercard/page.php?id=110926698934250">Bridewell bar</a>';
$regxp = '/Has worked at \<(.*)\>(.*?)\</i';
if(preg_match($regxp, $str, $re)) {
  echo $re[2];           // Bridewell bar
}

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.