Jump to another part of the php-file

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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Jump to another part of the php-file

Post by vigge89 »

Is there any way to jump to another part in the PHP-file?
like in Visual Basic, u can have this code:

Code: Select all

On error goto errhandler 'On error goto errhandler
goto part 'Goto part

Exit Sub

part:
'This is were something will be done
Exit sub

errhandler:
msgbox "Error.....bla bla bla"
Exit Sub
Is this possible in PHP?
becuase i've created a function that opens a file, reads from it, and the closes it etc.

But if there is an error;

Code: Select all

<?php
@fwrite ($fp, $newcontent) or [*inputsomething here*];
?>
It should goto another part of the script.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

<?php
function error ($msg)
{
   echo $msg;
      exit;
}

// ...
// code
// ...

if (fwrite ($fp, $newcontent))
{
  // exec more code
} else {
  error("Doh!");
}
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

oh, never thought of that ;)
i'll try it out tomorrow :D
Post Reply