Hi,
I'm new to PHP, I'm having trouble finding a way to replace a '_' in a
string with a space.
i.e using 'eregi_replace' I want to change
'United_Kingdom' to
'United Kingdom'
--
VS 12 10790
$string = "United_Kingdom";
$string = str_replace ("_", " ", $string);
Have fun ;)
$my_string = "United_Kingdom";
$my_new_string = str_replace("_", " ", $my_string);
echo "$my_new_string"; //this will output United Kingdom
When you use str_replace(), you need to give it 3 elements. The first is the
character you want to replace, the second is the character to replace it
with, and the third is the string you want to modify.
You can find more info on it at www.php.net/str_replace
--
-Brandon Rohde
"VS" <vs@nospam.blueyonder.invalid> wrote in message
news:b%******************@fe3.news.blueyonder.co.u k... Hi,
I'm new to PHP, I'm having trouble finding a way to replace a '_' in a string with a space.
i.e using 'eregi_replace' I want to change
'United_Kingdom' to
'United Kingdom'
-- VS
Hello! echo "$my_new_string"; //this will output United Kingdom
Why do you use
echo "$my_new_string";
instead of
echo $my_new_string;
?
Greetings,
Hero Wanders
Well, using the method without quotes is obviously fine for just printing
the variable. It's late at night, so I added the quotes by habit :)
--
-Brandon Rohde
"Hero Wanders" <he*******@nexgo.de> wrote in message
news:di*************@news.t-online.com... Hello!
echo "$my_new_string"; //this will output United Kingdom
Why do you use echo "$my_new_string"; instead of echo $my_new_string; ?
Greetings, Hero Wanders
> It's late at night, so I added the quotes by habit :)
Hehe, in Poland that's two o'clock :P
Hello! Well, using the method without quotes is obviously fine for just printing the variable. It's late at night, so I added the quotes by habit :)
Hmm, i _never_ use "$foo".
Concatenation is done by using the dot:
$foo.$bar.$baz (not "$foo$bar$baz").
Please explaing your habit :-)
Greetings,
Hero Wanders
> $string = "United_Kingdom"; $string = str_replace ("_", " ", $string);
couldn't you also use preg_replace()? would that be faster?
Oliver Saunders said the following on 18/10/2005 18:06: $string = "United_Kingdom"; $string = str_replace ("_", " ", $string);
couldn't you also use preg_replace()? would that be faster?
You could preg_replace(), but I would imagine it would be orders of
magnitude slower, because regex-based matching is far more complex than
simple sub-string matching.
--
Oli
If Brandon is like me, he took the habit from frequently doing things
like
echo "Hi, my name is $name and my age is $age!";
Greetings
$string = str_replace ("United_Kingdom", "United Kingdom", $string);
is that what you want?
/f3l
Samuel wrote: If Brandon is like me, he took the habit from frequently doing things like
echo "Hi, my name is $name and my age is $age!";
Greetings
Please leave enough of the original post intact so that those with
clients who expire posts faster than others know what the context is.
Just because this is the habit you picked up, it does not make it a good
habit to have. Why would you have php do the contatenation and provide
additional overhead when you can do it yourself? If it's a matter of
laziness, then you should rethink your profession.
-Joe
>Just because this is the habit you picked up, it does not make it a good habit to have. Why would you have php do the contatenation and provide additional overhead when you can do it yourself? If it's a matter of laziness, then you should rethink your profession.
Whoa. You just read a casual comment and in 50 words jumped to the
conclussion that I should sit back and reconsider my entire
professional life. That's got to be a new world record or something,
specially considering I never said it was a good habit... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Little PussyCat |
last post by:
Hello,
I need to be able to replace only the first occurance of a space character
in a column.
Reason being is the data in the column I am trying to replace seems to have
umpteen space...
|
by: Epetruk |
last post by:
If I have a snippet of javascript code like this:
var str = "This is a snippet;
str.replace(/ */gi,' ');
what should the call to replace do? My actual tests show that it inserts
spaces...
|
by: hagai26 |
last post by:
I am looking for the best and efficient way to replace the first word
in a str, like this:
"aa to become" -> "/aa/ to become"
I know I can use spilt and than join them
but I can also use regular...
|
by: Jim |
last post by:
Hey all, I have a dilemma.
I have a field in a table called "Supervisor." The table currently
has 1,500+ records. Sometimes, the HR download that populates the
field formats the field one way,...
|
by: Vic |
last post by:
Hi,
With VBA code from MSAccess, how to search for a string in another
text file, and replace it with space and then save it under the same
name? Your help is greatly appreciated.
Rgds
|
by: Neo Geshel |
last post by:
Greetings
I am using VB in my ASP.NET project that uses an admin web site to
populate a database that provides content for a front end web site. I am
looking for a way to use replace() to...
|
by: channu |
last post by:
Hi
I am beginner in c++ coding.I want to read a text file and replace
commas and space with tabs.
Can any buddy help me out.
Thanks
Channu
|
by: Pascal |
last post by:
bonjour hello
I would like to trim a string of all its white spaces so i used
myString.trim() but it doesn't work as supposed : unsecable space are
remaining in the middle of my string...
i...
|
by: Joe Cool |
last post by:
I need to map several columns of data from one database to another
where the data contains multiple spaces (once occurance of a variable
number or spaces) that I need to replace with a single...
|
by: Stijn VA |
last post by:
Okee, the story goes like this:
I have a string that can not contain spaces (It is retrieved from a
externat application...)
At first they replaced the spaces by '_' so somthing like "ABC DEF"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |