
November 14th, 2004
05:19 AM
Newbie needs help please :)
Could somebody direct to a thread or a link that explains
<?php
$homepage = trim($homepage1);
if ($homepage)
{
if (preg_match('#^www\.#si', $homepage))
{
$homepage = "http://$homepage";
}
else if (!preg_match('#^[a-z0-9]+://#si', $homepage))
{
// homepage doesn't match the [url]http://-style[/url] format in the beginning -- possible attempted exploit
$homepage = '';
}
}
?>
just the "preg_match" etc and the values inside the ('Stuff in, here') please?
thanks 
btw, this a homepage verification script 

November 14th, 2004
05:41 AM
Neverside Newbie
Status: Offline!
The si at the end means that it's case-insensitive and new lines are matched if a dot is written (for this script, you don't really need the s).
The ^ means NOT, so, ^www means: NOT 'www'. The dot matches any character.
^[a-z0-9]+ means NOT a letter or number repeating at least once (the repeating things is the plus). The :// is just a string, like www in the 1st example.
In any case, I don't think this script would actually work. But if it does, more power to you.
___________________
Learn HTML

November 14th, 2004
05:54 AM
well how would it check a urls info ? using this script can u explain ? 
<form>
<input type='text' name='formhtml' size='40'>
<br>
<br>
<input type='submit' value='submit' name='submit'>
</form>
<?
$submit = $_POST['submit'];
$userwebsite = $_POST['formhtml'];
if (isset($submit))//In here it checks the name they entered and checks to see if its [url]http://[/url]$userwebsite
{
echo "Click Here For Site: <a href='$userwebsite'>$userwebsite</a>";
}
else //this would be displayed if the website didnt match [url]http://www.[/url]$userwebsite
{
echo "learn how to type!";
}
?>

November 14th, 2004
07:22 AM
Neverside Newbie
Status: Offline!
<?php
if (preg_match("/http\:\\/\\//i", $string))
{
echo 'Valid URL';
}
else
{
echo 'Invalid URL';
}
?>
You can the <a tag yourself, as it would be inefficient to check with the <a tag.
___________________
Learn HTML
Last edited by Ynhockey, November 14th, 2004 07:29 AM (Edited 1 times)

November 14th, 2004
07:43 AM
why do you have the /http:\/\//i instead of just http://i ?

November 14th, 2004
08:28 AM
thinking of something witty to put here
Status: Offline!
Originally posted by Ynhockey
The si at the end means that it's case-insensitive and new lines are matched if a dot is written (for this script, you don't really need the s).
The ^ means NOT, so, ^www means: NOT 'www'. The dot matches any character.
^[a-z0-9]+ means NOT a letter or number repeating at least once (the repeating things is the plus). The :// is just a string, like www in the 1st example.
In any case, I don't think this script would actually work. But if it does, more power to you.
The caret (^) means 'starting with', not 'not'.

November 14th, 2004
08:44 AM
Neverside Newbie
Status: Offline!
Sorry, my bad, I forgot. ^ is NOT inside square brackets (again, plz correct me if I'm wrong).
But in any case, the code I posted on the last post should work.
why do you have the /http:\/\//i instead of just http://i ?
Because the forward slash is a special character in regex and needs to be escaped (with a backward slash). This also applies to dots, greater/less than signs, etc.
Btw, a slight correction to my code:
change: "/http to: "/\bhttp
___________________
Learn HTML
Last edited by Ynhockey, November 14th, 2004 08:46 AM (Edited 1 times)

November 14th, 2004
03:28 PM
bah, were did you guys learn all this
link me 

November 14th, 2004
03:43 PM
thinking of something witty to put here
Status: Offline!
Google for regular expressions.