escape quotes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

babyfighter
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Aug 05, 2002 6:24 am

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.

Jay

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!

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

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);?>">


Jay

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?>">
:)


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 0 guests