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!
Okay I need to figure out how to break out of this while statement. I'm searching the file $comparefile for a duplicate link ($newlink). The script executes and then stops when $newlink != $word. But I need to be able to break out to send an error message when a match is found. Thanks.
<?php
$fp = fopen("templates/links.txt", 'r');
$comparefile = fgets($fp);
$delims = """";
$word = strtok($comparefile, $delims);
while (is_string($word)) {
if($newlink == $word)
{
echo "Link has already been used."
break 2; //break out of the if statement and the while statement
}
if (!empty($word)) {
print "$word <br>";
}
$word = strtok($delims);
}
?>
There are many other ways to avoid this, you rarely see "break" used.
Thanks Duff the code worked great! But I'm sure that's no suprise. I was so close I could smell it. MMMMMMMMM SILICONE! I knew the elements I needed but didn't quite know how to make it come together.....