Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

escape quotes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

escape quotes

Postby babyfighter » Mon Aug 19, 2002 6:47 am

I am trying to send a user-defined string as a hidden variable in a form. The string has single quotes and double quotes in it. When I attempt to pass the string and print it on the next page, it gets cut off mid-string due to the presence of the quotes in the string. Here is a little sample of what I'm doing:

<?php

print ("<INPUT TYPE=hidden NAME='TaskDescription' VALUE='".$TaskDescription."'>");

?>

//THEN ON THE NEXT PAGE I HAVE THIS CODE:

print ($TaskDescription);


Needless to say it's been very frustrating trying to solve this. Anybody have any quick solutions for this problem? Thanks a lot.
babyfighter
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Aug 05, 2002 6:24 am

Postby Jay » Mon Aug 19, 2002 8:55 am

Code: Select all
$TaskDescription = str_replace('"',"&quot;",$TaskDescription);

Just slip that in somewhere before you output it!
Jay
 

Re: escape quotes

Postby WiZARD » Mon Aug 19, 2002 10:31 pm

babyfighter wrote:I am trying to send a user-defined string as a hidden variable in a form. The string has single quotes and double quotes in it. When I attempt to pass the string and print it on the next page, it gets cut off mid-string due to the presence of the quotes in the string. Here is a little sample of what I'm doing:

<?php

print ("<INPUT TYPE=hidden NAME='TaskDescription' VALUE='".$TaskDescription."'>");

?>

//THEN ON THE NEXT PAGE I HAVE THIS CODE:

print ($TaskDescription);


Needless to say it's been very frustrating trying to solve this. Anybody have any quick solutions for this problem? Thanks a lot.

try this:
Code: Select all
?>
<INPUT TYPE=hidden NAME="TaskDescription" VALUE="<? echo($TaskDescription);?>">

User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Re: escape quotes

Postby Jay » Tue Aug 20, 2002 2:57 am

WiZARD wrote:try this:
Code: Select all
?>
<INPUT TYPE=hidden NAME="TaskDescription" VALUE="<? echo($TaskDescription);?>">


That doesn't address the original problem.

Even so, it's far neater to write
<input type=hidden name="TaskDescription" value="<?=$TaskDescription?>">
:)
Jay
 


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron