Page 1 of 1

[SOLVED] strpos not working..

Posted: Tue Apr 11, 2006 3:41 am
by malcolmboston
im using this code to check if a link exists on a page...

Code: Select all

function checkBackLink () {
		// get the backlink we're looking for
		#echo 'im looking for '.$this->backLink.'';
		// now we have what we need to search for
		if (strpos($this->sourceCode, $this->backLink) === TRUE) {
			$this->hasBackLink = TRUE;
		} else {
			$this->hasBackLink = FALSE;
		}
	}
which basically checks for the link "http://www.discoworlduk.co.uk" in the source code of the page "http://web-camera.fcamera.info/links3/"

now its there, ive checked the source matches exactly, i dont understand why its returning false, im doing no htmlentities() (ie < is a < not <)

can someone help me out here

link to script: http://82.13.252.91/example.php

it has var_dump so u can see what its looking for

tbh im baffled

Posted: Tue Apr 11, 2006 3:45 am
by AKA Panama Jack
You could always use strstr instead.

Posted: Tue Apr 11, 2006 3:51 am
by malcolmboston
using....

Code: Select all

if (strstr($this->backLink, $this->sourceCode) ) {
			$this->hasBackLink = TRUE;
		} else {
			$this->hasBackLink = FALSE;
		}
also fails, its there, both variables are set, no warnings with full error reporting i can view source and find the string

why oh why 8O

Posted: Tue Apr 11, 2006 4:03 am
by JayBird
This line

Code: Select all

if (strstr($this->backLink, $this->sourceCode) ) {
Should be

Code: Select all

if (strstr($this->sourceCode, $this->backLink) ) {

your first method wont work becuase strpos() "Returns the numeric position of the first occurrence of needle in the haystack string"