473,414 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

question about str_replace function

26
Hi all,

I got a doubt about the str_replace function.

[PHP]<?php
$string="avenue 1, ave 1";
$words=str_replace ("ave","avenue", $string);
echo $words;
?>[/PHP]

the php code above will return me "avenuenue 1, avenue 1". i expect the result will be "avenue 1, avenue 1". any idea of how can i get such result?

Thank you

Regards,
Kencana
Jan 8 '07 #1
2 1106
kamill
71
try with this example....[PHP]<?php
arr = array("avenue 1", "ave 1");
print_r(str_replace("ave","avenue",$arr,2));
?> [/PHP]
Jan 8 '07 #2
Hi,

use this instead of str_replace.
We need more complex search and replace functionality so we use PCRE (Perl Compatible Regular Expressions).

[php]
$words=preg_replace("/\bave\b/si","avenue", $string);
[/php]

Svet
Jan 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
4
by: Noyb | last post by:
Posted this a while ago, never got so much as a peep. Please take a look and give any thoughts. I've set up a news links section using the RSS parsing tutorial found here:...
9
by: Hugo Coolens | last post by:
I need to use the str_replace function for a php-script which works together with html/javascript. In the script I have to perform things like: $arabic=str_replace ("'","\'", $row);...
6
by: Jimmy Clay | last post by:
I have a very basic question about how to include files to be used by another file. I'm trying to include a bad word filter into the guestmap on my website. I know almost nothing about PHP code....
1
by: marcomputers | last post by:
Hi, I'm trying to automatically update an existing rss podcast file using php and the str_replace function. Every time I add a media file, it should read the .rss file into a string, take the...
3
by: Eric Capps | last post by:
I am trying to open a directory on a file server to populate a drop down menu. I've been able to do this, but the results are not sorted alphabetically. How would I go about this? I've looked at...
2
by: zek2005 | last post by:
Hi !!! I have the following php code <?php $db = mysql_connect("1", user, password) or die ("can´t connect"); mysql_select_db(efemerides,$db); mysql_close(); ?>
4
by: d1srupt3r | last post by:
I am developing my form into a captcha secured form and I used header() function if the user didn't put the verification code properly and still when the user go back to the form page the filled he...
5
by: jmark | last post by:
I saw this example in php.net // Outputs: apearpearle pear $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text);...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.