Search Options
close
Search the following clips:
All Clips
Everyone's Clips
My Guides
Sign Up
Install
Learn More
Login
php - str_replace() examples
nouse4name
follow
0
4-30-2007 10:13 AM
209 views
tags:
php
,
str_replace()
Add a Comment
Login
to Comment. Not a member yet?
Sign up
Related Clips
2008 San Francisco Civil Grand Jury Report...
Hezbollah Brigades Propaganda Specialist C...
Report Slams 'Striking Lack of Recollectio...
SciFiPedia
Software Testing Patterns
Sexiest Bond girls according to Maxim
Recopilatorio de webs para ver Pelis OnLine
More clips from
nouse4name
A Story About Wolves
Oscmax: Error: 1054 unknown column shippin...
oscmax / oscommerce: bug: order details mi...
Today's Top Clips
Skeletal Cartoons
Apollo 14 astronaut claims aliens HAVE made contact
Kurt Vonnegut: How to Write with Style
6 Plants That Will Grow (Almost) Anywhere
More bad news for alarmists
Richest Americans See Their Income Share Grow
NASA: 70% of climate change due to Pacific oscillations, not CO2
Europe's worst genocide since Hitler
Good riddance
A lost world made by women
visit the
Top Clips page
View the Top Clips from
April 30, 2007
Embed This Clip In Your Site...
<div style="margin: 12px 0px; font-family: arial; color: #333333; background: #ffffff; border: solid 4px #e5e5e5; width: 100%; clear: left;"><div class="CM_CTB_Content_Wrap" style="margin: 0px; padding: 0px;background-color: #ffffff;"><div style="border-bottom: solid 1px #dcdcdc; white-space: nowrap; margin-bottom: 8px; background-color: #eeeeee ;background-image: url(http://www.clipmarks.com/images/source-bg.gif); background-repeat: repeat-x; height: 24px; line-height: 24px; vertical-align: middle; padding-bottom: 4px; color: #666666; font-size: 10px;" ><a href="http://clipmarks.com/clip-to-blog/" title="see clips that are hot right now"><img src="http://content.clipmarks.com/blog_embed/eb2228ce-ae20-4bd9-986e-f5022ab209d3/9867162C-F9AE-40E7-B7B5-062EFA9EF6C5/" alt="" width="19" height="19" border="0" style="vertical-align: middle; margin: 0px 4px; display: inline; border: none; float:none;" /></a>clipped from <a title="http://www.php.net/str_replace" href="http://www.php.net/str_replace" style="font-size: 11px;">www.php.net</a></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.php.net/str_replace"><SPAN class="default"><?php </SPAN><SPAN class="comment">// Provides: <body text='black'> </SPAN><SPAN class="default">$bodytag </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">str_replace</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"%body%"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"black"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"<body text='%body%'>"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="comment">// Provides: Hll Wrld f PHP </SPAN><SPAN class="default">$vowels </SPAN><SPAN class="keyword">= array(</SPAN><SPAN class="string">"a"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"e"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"i"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"o"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"u"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"A"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"E"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"I"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"O"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"U"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">$onlyconsonants </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">str_replace</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$vowels</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">""</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"Hello World of PHP"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="comment">// Provides: You should eat pizza, beer, and ice cream every day </SPAN><SPAN class="default">$phrase </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"You should eat fruits, vegetables, and fiber every day."</SPAN><SPAN class="keyword">; </SPAN><SPAN class="default">$healthy </SPAN><SPAN class="keyword">= array(</SPAN><SPAN class="string">"fruits"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"vegetables"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"fiber"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">$yummy </SPAN><SPAN class="keyword">= array(</SPAN><SPAN class="string">"pizza"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"beer"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"ice cream"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">$newphrase </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">str_replace</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$healthy</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$yummy</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$phrase</SPAN><SPAN class="keyword">); </SPAN><SPAN class="comment">// Use of the count parameter is available as of PHP 5.0.0 </SPAN><SPAN class="default">$str </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">str_replace</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"ll"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">""</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"good golly miss molly!"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$count</SPAN><SPAN class="keyword">); echo </SPAN><SPAN class="default">$count</SPAN><SPAN class="keyword">; </SPAN><SPAN class="comment">// 2 // Order of replacement </SPAN><SPAN class="default">$str </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"Line 1\nLine 2\rLine 3\r\nLine 4\n"</SPAN><SPAN class="keyword">; </SPAN><SPAN class="default">$order </SPAN><SPAN class="keyword">= array(</SPAN><SPAN class="string">"\r\n"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"\n"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"\r"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">$replace </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">'<br />'</SPAN><SPAN class="keyword">; </SPAN><SPAN class="comment">// Processes \r\n's first so they aren't converted twice. </SPAN><SPAN class="default">$newstr </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">str_replace</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$order</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$replace</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$str</SPAN><SPAN class="keyword">);</SPAN></blockquote></div><div style="margin: 0px 6px 6px 4px;"><table style="font-size: 11px;border-spacing: 0px;padding: 0px;" cellpadding="0" cellspacing="0" width="100%"><tr><td style="background:transparent;border-width:0px;padding:0px;"> </td><td align="right" style="background:transparent;border-width:0px;padding:0px;width:107px" width="107"><a href="http://clipmarks.com/share/9867162C-F9AE-40E7-B7B5-062EFA9EF6C5/blog/" title="blog or email this clip"><img src="http://content9.clipmarks.com/images/c2b-foot.png" border="0" alt="blog it" width="107" height="17" style="border-width:0px;padding:0px;margin:0px;" /></a></td></tr></table></div></div>
Clipmarks
Home
New Clips
Top Clips
Dashboard
Popular Topics
News
Life
Science
Technology
Entertainment
Get Started
Sign Up
Install Clipping Tool
How Clipping Works
Clip-to-Blog™
ClipSearch
Tools and Resources
FAQ
ClipWeek
Top Clippers
Top Tags
Site Map
About Clipmarks
About Us
Contact
Blog
Copyright
Privacy
EULA
OK