Regular Expresions?

Status
Not open for further replies.

ziycon

New Member
What I'm trying to do is to validate a link input, say a link like site.com is input I need to check and make sure www. is added or if http://www.site.com is input I need to remove the http://.

I need every link to be formatted like www.site.com, any help much appreciated.
 

louie

New Member
$pattern = '/(href\s?=\s?)([\'|"])([^\'|"]*)([\'|"])/si';
preg_match_all($pattern,$content,$patterns);
$result = $patterns[0];
//print_r($patterns[0]);
foreach($result as $y){
//check to links to make sure are formated as it should and do some replacing if not

}

hope this help. I know is vague but I need to know the content submited and how links are formated in the first place.
 

louie

New Member
Will they have an option to enter a link like a pop-up box or similar, because if not most content is treated as plain text and looking to match any links will be close to impossible and pron to mistakes.

if the link will be posted as
Code:
<a href='link to'>LINK</a>
than the code I gave you will match them otherwise I wish you good luck with it.
 

ziycon

New Member
I'll try give a detailed explaination. There is a textbox and a submit button on a page, the user enters the URL and clicks submit. It doesn't matter what the link is.

The value from the textbox is retrieved and then passed to a function to be formatted to be only www.site.com.

I'm currently using the below function but its not as robust as it should be to tackle any instance. I thought regular expressions would suit it better!?

if(isset($_REQUEST['domain'])) {
if(substr($_REQUEST['domain'],0,7) == "http://")
$domain = $_REQUEST['domain'];
else
$domain = "http://".$_REQUEST['domain'];
}
 
Status
Not open for further replies.
Top