ลักษณะการทำงานก็คือจะสร้างไฮเปอร์ลิงค์ให้โดยอัตโนมัติ
code
function replaceLinks($text) {
// convert support@pogoda.in into
// <a href="mailto:support@pogoda.in">
// support@pogoda.in</a>
$text = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*',
'<a href="mailto:\\0">\\0</a>',$text);// convert http://www.pogoda.in/new_york/eng/ into
// <a href="http://pogoda.in/new_york/eng/">
// pogoda.in/new_york/eng/</a>
$text = ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)',
'<a href="\\0">\\1</a>',$text);
// convert www.pogoda.in/new_york/eng/ into
// <a href="http://www.pogoda.in/new_york/eng/">
// www.pogoda.in/new_york/eng/</a>
$text = ereg_replace('(^| )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)',
' <a href="http://\\2">\\2</a>',$text);
return $text;
}
Example
echo replaceLinks('mailto:tatump@memo8.com');
echo"<br />";
echo replaceLinks('http://www.memo8.com/toolkits/')
หรือจะเอาไปดัดแปลงเป็นการอ่านมาจากไฟล์ก็ได้นะครับ
ที่มา : http://th2.php.net/eregi_replace
RSS Feed
Twitter
January 12th, 2008
admin | 991 views
Posted in
Tags: 
