Monday 18 October 2010

How to Find and Replace Text in MySQL Database?

Use the following syntax for replacing text in mysql:

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

SELECT REPLACE(‘www.mysql.com’, ‘my’, ‘you');

and result will be:

www.yousql.com

Cheers!

Friday 8 October 2010

How to remove hyperlink from a string using php?

<?php

function findAndReplace($arr) {
    return '<strong>'.$arr[1].'</strong>';
}

$inputText = 'Why use <a href="#"  style="padding-left:5px"> PHP </a>?';
echo "<br />Input is: <br />";
echo $inputText;

$returnText = preg_replace_callback('@<a(?:.*)>(.*)</a>@isU', 'findAndReplace', $inputText);

echo "<br /><br />Output will be: <br />";
echo $returnText;

?>

Input is:
Why use PHP ?

Output will be:
Why use PHP ?