[SOLVED] strpos not working..

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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

[SOLVED] strpos not working..

Post 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
Last edited by malcolmboston on Tue Apr 11, 2006 4:37 am, edited 1 time in total.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

You could always use strstr instead.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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"
Last edited by JayBird on Tue Apr 11, 2006 4:04 am, edited 1 time in total.
Post Reply