By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,824 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,824 IT Pros & Developers. It's quick & easy.

string replace in php..?

nirmalsingh
100+
P: 218
hi all,
i am newbee to php,
for example
Expand|Select|Wrap|Line Numbers
  1. $mydata="my name is "Nirmal" Singh";
  2. echo $mydata;
  3.  
i want the result as
my name is Nirmal Singh
what should i do for this?
Feb 9 '07 #1
Share this Question
Share on Google+
7 Replies


Motoma
Expert 2.5K+
P: 3,235
Hope these help:

[PHP]
$mydata="my name is Nirmal Singh";
echo $mydata;
// my name is Nirmal Singh

$mydata = "My name is ""Nirmal"" Singh";
echo $mydata
// My name is "Nirmal" Singh

$mydata = "My name is \"Nirmal\" Singh";
echo $mydata
// My name is "Nirmal" Singh

$mydata = 'My name is "Nirmal" Singh';
echo $mydata
// My name is "Nirmal" Singh
[/PHP]
Feb 9 '07 #2

nirmalsingh
100+
P: 218
i have already fixed data in $mydata as
my name is "Nirmal" Singh
now i want to regenerate $mydata as
my name is Nirmal Singh
what should i do?
i hope u understand my question.
Feb 9 '07 #3

Motoma
Expert 2.5K+
P: 3,235
i have already fixed data in $mydata as
my name is "Nirmal" Singh
now i want to regenerate $mydata as
my name is Nirmal Singh
what should i do?
i hope u understand my question.
I don't understand your question, because
[PHP]
$mydata="my name is "Nirmal" Singh";
echo $mydata;
[/PHP]
will give you an error.
Feb 9 '07 #4

Nert
P: 64
i have already fixed data in $mydata as
my name is "Nirmal" Singh
now i want to regenerate $mydata as
my name is Nirmal Singh
what should i do?
i hope u understand my question.
hi nirmalsingh,

your question is a bit confusing.., if you don't mind would you please post more info about what you really want to achieve. Motoma is right, this code
[PHP]$mydata = "my name is "Nirmal" Singh";
echo $mydate;[/PHP] would give you an error.
Feb 9 '07 #5

nirmalsingh
100+
P: 218
my problem is that, even if a string contains " symbol, i want to make it accept such as that " is not end of a string. what should i do?
Feb 9 '07 #6

Motoma
Expert 2.5K+
P: 3,235
my problem is that, even if a string contains " symbol, i want to make it accept such as that " is not end of a string. what should i do?
Take a look at the examples I posted. They gave instructions on doing just that.
Feb 9 '07 #7

ronverdonk
Expert 2.5K+
P: 4,258
i have already fixed data in $mydata as
my name is "Nirmal" Singh
now i want to regenerate $mydata as
my name is Nirmal Singh
what should i do?
i hope u understand my question.
Just remove the double quotes from your string using str_replace:[php]$myname = str_replace('"', '', $myname);[/php]
Ronald :cool:
Feb 10 '07 #8

Post your reply

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