Connecting Tech Pros Worldwide Help | Site Map

string replace in php..?

nirmalsingh's Avatar
Familiar Sight
 
Join Date: Sep 2006
Location: Madurai - India
Posts: 217
#1: Feb 9 '07
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?
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#2: Feb 9 '07

re: string replace in php..?


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]
nirmalsingh's Avatar
Familiar Sight
 
Join Date: Sep 2006
Location: Madurai - India
Posts: 217
#3: Feb 9 '07

re: string replace in php..?


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.
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#4: Feb 9 '07

re: string replace in php..?


Quote:

Originally Posted by nirmalsingh

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.
Nert's Avatar
Member
 
Join Date: Nov 2006
Location: Philippines
Posts: 64
#5: Feb 9 '07

re: string replace in php..?


Quote:

Originally Posted by nirmalsingh

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.
nirmalsingh's Avatar
Familiar Sight
 
Join Date: Sep 2006
Location: Madurai - India
Posts: 217
#6: Feb 9 '07

re: string replace in php..?


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?
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#7: Feb 9 '07

re: string replace in php..?


Quote:

Originally Posted by nirmalsingh

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.
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#8: Feb 10 '07

re: string replace in php..?


Quote:

Originally Posted by nirmalsingh

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:
Reply


Similar PHP bytes