Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
hotnoob > Intel > Tutorial: String Replacing with PHP

qondio.com/5TZy PRINT EMAIL

Tutorial: String Replacing with PHP

Tutorial name: Text Filtering with PHP
You're experience: Advanced
Difficulty: Novice
Time Taken: 20-60 seconds
Plug-ins needed: none.

Replacing strings with other strings is fairly easy, and the following code will show you how to do so.
Code:
<?php
$string = "I like you";
echo $string . "\n";
$string = str_replace("like", "love", $string); //str_replace(what to change, what to change to, the input);
echo $string . "\n"; // you will end up with, "i love you"
?>


Now to be a bit creative
Code:
<?php
$patterns = array(":)", ":(", ":O", "Wow...");
$replacements = array("I'm Happy!", "I'm Sad", "I'm Shocked!", "OMFG that was AMAZING, like WOW!");
$string = "I am a very good actor! :), :(, :O, they loved it, everyone said, \"Wow...\"\n";
echo $string;
$string = str_replace($patterns, $replacements, $string);
echo $string;
// it should end up as, "I am a very good actor! I'm Happy!, I'm Sad, I'm Shocked!, they loved it, everyone said,
// "OMFG that was AMAZING, like WOW!"
?>

A Noobs World © 2007 - 2008

Contributed by hotnoob on April 8, 2008, at 1:00 AM UTC.

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

Share

Copyright Notice

The copyright for this content entitled "Tutorial: String Replacing with PHP" has been specified by the contributor as:

All Rights Reserved

This content may not be copied, distributed or adapted by anyone under any circumstances.

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by hotnoob

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK