• New Scripts
  • Popular Scripts
  • Top Scripts
  • Rss feed

Php Scripts

  • PHP Scripts
  • How to Add Link
  • Sponsor Listing
  • Login
  • Register
  • Getting Rated
  • Blog
  • Home
  • Subscribe to Feed
Blog > Tutorials > PHP Scripts > PHP Scripts replace string str_replace()

PHP Scripts replace string str_replace()

Posted on March 13, 2010, 12:46 pm, by Scripts, under PHP Scripts.

PHP Scripts replace string function str_replace()

This is a very good function to replace the word or string in string or text area, and very easy to handle the string.

 <?php $string = "PHP-Scripts-string-change-function";
echo $string; ?> 

//Output as below PHP-Scripts-string-change-function

Now replace the – into space

<?php $string = "PHP-Scripts-string-change-function";

$change = str_replace("-", " ", $string); ?>

Out put
PHP Scripts string change function

We can also use the array to change the string like below

<?php  $string="I have two shirt one is blue and other is red color";
// we change the three word shirt to pent, blue to brown and red to yellow
$oldword = array("shirt", "blue","red");
$newword = array("pent","brown","yellow");
$newstring = str_replace($oldword, $newword, $string);

// Output now is

// I have two pent one is brown and other is yellow color ?>

You can easily replace the world and string.

Tags: PHP Scripts, str_replace()
Comment (RSS)  |  Trackback

Leave a Reply

Click here to cancel reply.

Spam Protection by WP-SpamFree

« SEO Friendly URLs with PHP | mod_rewrite | .htaccess
PHP Image Gallery »

Categories

  • Announcements
  • Best Scripts
  • Tutorials
  • JavaScripts
  • PHP Scripts

Tags

htaccess image gallery include jquery mod_rewrite photo gallery PHP PHP Scripts radio button SEO SEO Friendly URLs show/hide str_replace() Tutorials

Web Hosting



Home | Feedback | Privacy | Advertise with us
(c) Copyright 2006 AdvanceScripts™. All rights reserved.
No part of this website may be reproduced, copied and/or distributed in any medium without express written permission
Trademarks are property of their respective owners
Site Developed and Hosted by Ethic Solutions