Page 1 of 1

Finding Url in a webpage

Posted: Sat Apr 14, 2007 6:39 am
by firefox
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Good Morning Team,

I have a headache I cannot solve, I am trying to use php code to find a url on a webpage can anyone help please, this is how far I have got with no success...

Code: Select all

<?php

$aText ='http://www.sapphire-team.com';
$aUrl = 'http://www.highforce.com/resource/Business-Directories-and-Search-Engines.html';

  $filepointer = fopen ( $aUrl, "r" );
  
    if ( $filepointer )
  {
    while ( ! feof ( $filepointer ) )
    {
      $buffer = fgets ( $filepointer, 4096 );
      $file .= $buffer;
    }

$pattern = '^$aText^i';

$a =  preg_match($pattern, $file);
if ($a) { echo "Found the frigging link at last!"; }
else {echo "link not found";}
  }
  

?>
Thanks in Advance from Alan


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Apr 14, 2007 7:19 am
by mentor
simply use strpos()

Posted: Sat Apr 14, 2007 7:27 am
by firefox
mentor wrote:simply use strpos()
No sorry that does not work...

All the best from Alaan

Posted: Sat Apr 14, 2007 7:46 am
by mentor
use this code

Code: Select all

<?
$aText ='http://www.sapphire-team.com'; 
$aUrl = 'http://www.highforce.com/resource/Business-Directories-and-Search-Engines.html'; 

$string = file_get_contents($aUrl);
if( strpos($string, $aText) !== false)
echo "found";
else
echo "not found";
?>

Posted: Sat Apr 14, 2007 8:17 am
by firefox
Hi Mentor,

Thank you very much that is great...

All the best from Alan phew !!!!!!!!!!!!!!!