Tuesday, 27 August 2013

PHP extract link from <a> tag

<?php

$string = "<a href=\"www.xyz.com/index.php\">My URL</a>\n";
preg_match('|<a.+?href\="(.+?)".*?>(.+?)</a>|i', $string, $match);
$url = $match[1];
$text = $match[2];
echo "Link: ".$url;
echo "Url: ".$text;
?>

Output:
Link: www.xyz.com/index.php
Url: My URL

Friday, 9 August 2013

Javascript Email validation including domains with dashes

Java Script Email validation including domains with dashes using Regular Expressions

$match = (/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/);