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!
This blog will give you all kind of Open Source help like Drupal, Zend, Symfony, Joomla and Magento.
Monday, 18 October 2010
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 ?
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 ?
Wednesday, 29 September 2010
How to create Custom Error Messages in Apache?
Below is the way to create custom error message using Apache:
Below is an example of a .htaccess file, just copy and paste into your file, but change the paths:
Examples:
Full path would be http://www.yourwebsite.com/path_to_your_error_file_or_script
Absolute path would be /home/yoursite.com/path_to_your_error_file_or_script
Relative path would be /path_to_your_error_file_or_script
To summarise the steps, they are as follows:
Cheers!
Below is an example of a .htaccess file, just copy and paste into your file, but change the paths:
ErrorDocument 404 /path_to_your_error_file_or_script
ErrorDocument 403 /path_to_your_error_file_or_script
ErrorDocument 403 /path_to_your_error_file_or_script
ErrorDocument 500 /path_to_your_error_file_or_script
Examples:
Full path would be http://www.yourwebsite.com/path_to_your_error_file_or_script
Absolute path would be /home/yoursite.com/path_to_your_error_file_or_script
Relative path would be /path_to_your_error_file_or_script
To summarise the steps, they are as follows:
- Create a text file, and add to it a line for each error and rename it .htaccess
- Upload the files/script that the .htaccess file calls in each error.
- TEST! By typing a weird URL in the address box - you should get the 404 custom error.
Cheers!
How to store UTF8 (indian language) data in mysql?
We assume we have a DataBase with table news, and a column named posts, which will save the news written in your website.We know that all major DataBase’s support UTF8. And we shall explore that feature.
Now we write a article in hindi, हेल्लो वर्ल्ड
If the UTF8 is not specified, you should see something like ?????? in ur DataBase otherwise you should see the hindi data. Clear? Now lets see the code given below:
First check for UTF8 compatibility with this query. If it supports you should see the output as “Character_set_system”| “UTF8″
SHOW VARIABLES LIKE ‘character_set_system’;
this will show the below result if support:
Now that being checked, alter the table and just modify the column, which is 'text' in our above example and specify it as UTF8
ALTER TABLE news MODIFY text VARCHAR(200) CHARACTER SET UTF8;
Then execute following query before inserting into the table:
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
Now, try to insert the hindi value and save it. Query it and u should see the hindi text
Cheers!
Now we write a article in hindi, हेल्लो वर्ल्ड
If the UTF8 is not specified, you should see something like ?????? in ur DataBase otherwise you should see the hindi data. Clear? Now lets see the code given below:
First check for UTF8 compatibility with this query. If it supports you should see the output as “Character_set_system”| “UTF8″
SHOW VARIABLES LIKE ‘character_set_system’;
this will show the below result if support:
| Variable_name | Value |
|---|---|
| character_set_system | utf8 |
Now that being checked, alter the table and just modify the column, which is 'text' in our above example and specify it as UTF8
ALTER TABLE news MODIFY text VARCHAR(200) CHARACTER SET UTF8;
Then execute following query before inserting into the table:
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
Now, try to insert the hindi value and save it. Query it and u should see the hindi text
Cheers!
Wednesday, 11 August 2010
How to make database IP live using ubuntu?
$ vi /etc/mysql/my.cnf
search bind_address..
comment bind_address..
$ sudo -s -H
$ ls -l /etc | grep my
$ ls -l /etc/mysql | grep my
$ /etc/init.d/mysql restart
$ mysql -u root -p
mysql > show grants;
Now you will see the following query:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION
Copy above query and paste it into terminal and replace 'localhost' by %.
mysql > flush privileges;
Cheers!
search bind_address..
comment bind_address..
$ sudo -s -H
$ ls -l /etc | grep my
$ ls -l /etc/mysql | grep my
$ /etc/init.d/mysql restart
$ mysql -u root -p
mysql > show grants;
Now you will see the following query:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION
Copy above query and paste it into terminal and replace 'localhost' by %.
mysql > flush privileges;
Cheers!
Monday, 19 July 2010
How to unzip tar.gz file in ubuntu?
Hi guys,
Please use the following command:
tar xvzf something.tar.gz
Cheers!
Please use the following command:
tar xvzf something.tar.gz
Cheers!
Sunday, 18 July 2010
The 8 ball problem?
Hie All,
Please use the following and get the result in 2 iteration:
You can identify the heavier ball in only 2 weighings!
The secret is not to get fooled into the "divide and conquer" approach where the input is halved in each iteration as explained above.
To achieve this in only 2 weighings, you first put 3 balls in each bowl on the scale, e.g. {1,2,3} against {4,5,6}.
Should the scale balance, you have only 2 balls remaining which you can compare by putting each in a separate bowl on the scale, e.g. {7} against {8}.
Should the scale not balance, however, take the 3 balls from the heavier bowl on the scale (e.g. 1,2,3).
Pick any 2 balls and compare these against each other, e.g. {1} against {2}. If the scale balances, you know it is ball 3 is the heavier. Is the scale moving, you know it's the ball on the heavier side.
Thanks & Cheers!
Please use the following and get the result in 2 iteration:
You can identify the heavier ball in only 2 weighings!
The secret is not to get fooled into the "divide and conquer" approach where the input is halved in each iteration as explained above.
To achieve this in only 2 weighings, you first put 3 balls in each bowl on the scale, e.g. {1,2,3} against {4,5,6}.
Should the scale balance, you have only 2 balls remaining which you can compare by putting each in a separate bowl on the scale, e.g. {7} against {8}.
Should the scale not balance, however, take the 3 balls from the heavier bowl on the scale (e.g. 1,2,3).
Pick any 2 balls and compare these against each other, e.g. {1} against {2}. If the scale balances, you know it is ball 3 is the heavier. Is the scale moving, you know it's the ball on the heavier side.
Thanks & Cheers!
Subscribe to:
Posts (Atom)