Jump to content

[SOLVED] Result of a search to a string?


dmarquard

Recommended Posts

I can't seem to find any functions on php.net that can achieve this, so my guess is that it will require an assortment of functions or regular expressions.

 

Basically, I need to first search for the resulting code you'll see below, and then grab ONLY the URL contained in the following code and assign it the $result variable.

 

    <h3 id="title">
        <a href="http://www.sendmeto.com/a/string/" rel="dc:source" property="dc:title" target="_blank">

 

The above snippet comes from a webpage with much more source code, but I think I provided enough to go on.

Link to comment
https://forums.phpfreaks.com/topic/103403-solved-result-of-a-search-to-a-string/
Share on other sites

<?php
$code = '<h3 id="title">
        <a href="http://www.sendmeto.com/a/string/" rel="dc:source" property="dc:title" target="_blank">';
if(preg_match('/<h3 id="title">\s+<a href="(.+?)"/',$code,$matches)){
  $result = $matches[1];
  print $result;
}else{
  print "No Match";
}
?>

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.