0

i feel this is going to be something stupid but i cant seem to get this to work what im trying to do is read through a file and extract all the appropriate web addresses but when i run this i get a fatal error, i get the feeling im initiating an infinate loop but i cant find it

    $contents = file_get_contents("../uploads/bookmarks.html");
$find   = 'https://www.example.net/e/';
$i = 0;
do{
    if(strpos($contents, $find)){
        $check = true;
        $contents = strstr($contents,$find);
        $temp = explode('"', $contents, 2);
        echo $temp[0];
    }else{
        $check = false;
    }
}while($check = true);
0

1 Answer 1

3

You are assigning $check = true instead of comparing the two values. Turn

while($check = true)

to

while ($check === true)

Sign up to request clarification or add additional context in comments.

7 Comments

@Sebas has a 'better' solution of just using while($check). It is less redundant.
@Jasper Actually assignment happens before the expression is checked. Or else the old standard while($row = mysql_fetch($res)) would infinite loop.
Ignore me, I've been coding JS all day.
@Sebas Or for those who aren't into the whole brevity thing: while($check === true) :)
On that note, I'd also change strpos($contents, $find) to something more explicit like strpos($contents, $find) !== false. I don't really like the chameleon aptitude of the php functions returns...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.