Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i handle speech marks in a variable 2

Status
Not open for further replies.

panini

MIS
Jun 1, 2001
136
GB
hi there - i have a string that needs to have -ds1"data" in it - but the first " keeps closing the string...

In asp in would be -ds1""data"" but i can't work out what it would be in php

 
hi there - that gives me

Unexpected character in input: '\' (ASCII=92) state=1
 
try the stripslashes() function with that


ex.

$str="hello world it\'s \"steven\".";

echo stripslashes($str);
 
Little typo from steven there. In ASP you escaped the double quotes by making two double quotes. In PHP you do it by putting a backslash character in front of the escaped quote:
Code:
$myString = "-ds1\"data\"";
An alternative available to PHP is using the other set of quotes. PHP understands strings in both single and double quotes. So, if you need to have a single quote in string, you can embed it in double quotes and if you need double quotes embed it in single:
Code:
$myString = '-ds1"data"';
 
Hmm, You might also consider using the htmlentities.
" = "

Code:
$myString = "-ds1"data"";

Code:
$myString = "-ds1" . htmlentities("\"data\"");

If the "data" is retrieved from a variable, you can simply wrap the variable in htmlentities().

eg:
Code:
$foo = htmlentities($bar);

This would also work for a submitted form, data retrieved from mysql, etc.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top