Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

80 users online



Newbie needs help please :)

Newbie needs help please :)

Currently viewing this thread: 1 (0 members and 1 guests)


LKR

LKR

Status: Offline!

Newbie needs help please :)

Could somebody direct to a thread or a link that explains

PHP:

<?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?

Sad thanks Smile

btw, this a homepage verification script Sad

Ynhockey

Ynhockey

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

LKR

LKR

Status: Offline!

well how would it check a urls info ? using this script can u explain ? Sad

PHP:


<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!";
}
?> 

Ynhockey

Ynhockey

Neverside Newbie
Status: Offline!
PHP:

<?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)

LKR

LKR

Status: Offline!

why do you have the /http:\/\//i instead of just http://i ?

Rad

Rad

thinking of something witty to put here
Status: Offline!
Quote:

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'.

Ynhockey

Ynhockey

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.

Quote:

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)

LKR

LKR

Status: Offline!

bah, were did you guys learn all this Smile link me Smile

Rad

Rad

thinking of something witty to put here
Status: Offline!

Google for regular expressions.

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0199 seconds.