Finding Url in a webpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
firefox
Forum Newbie
Posts: 6
Joined: Sat Jun 03, 2006 3:52 am

Finding Url in a webpage

Post 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]
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

simply use strpos()
firefox
Forum Newbie
Posts: 6
Joined: Sat Jun 03, 2006 3:52 am

Post by firefox »

mentor wrote:simply use strpos()
No sorry that does not work...

All the best from Alaan
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post 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";
?>
firefox
Forum Newbie
Posts: 6
Joined: Sat Jun 03, 2006 3:52 am

Post by firefox »

Hi Mentor,

Thank you very much that is great...

All the best from Alan phew !!!!!!!!!!!!!!!
Post Reply