Log in

View Full Version : What is the 3rd parameter?



kuau
11-07-2008, 12:47 AM
This code is supposed to check if the URL entered in the form starts with http://, and add it if it does not.


if( !ereg("^http://*", $ev_url, $regs) ) {
$ev_url = "http://" . $ev_url;
}

It doesn't seem to be working. The parts I don't understand are:


ereg ("^

and
$regs. I can find no $regs variable anywhere in the script.

Anyone know the best way to check a URL submitted through a form before inserting into a table?

Mahalo. erin :)

techietim
11-07-2008, 02:04 AM
No need for regex.


if(substr($URL, 0, 7) != 'http://')
$URL = 'http://' . $URL;

Twey
11-08-2008, 12:08 AM
The regex-free version is preferable (don't use regular expressions if it's easily expressed in another way, since regular expressions are very expensive), but to explain your earlier version: ereg() is a function that works on regular expressions, ^ in a regular expression means to only match at the beginning of the string (or line with the multiline flag), and $regs is assigned to by the ereg() function — that parameter of ereg() is a reference (http://www.php.net/references).