Jump to content

Recommended Posts

$var = "The length is 5' x 2" and blah blah";

 

<input type="text" name="textBox" value="<?php echo $var; ?>">

 

In the <input> this cuts off at the ' if I do value='' and the " if I do value ="" and at either if I just do value=

 

How do I get around this?

Link to comment
https://forums.phpfreaks.com/topic/128403-solved-question-about-form-fields/
Share on other sites

$var = "The length is 5' x 2" and blah blah";

 

<input type="text" name="textBox" value="<?php echo $var; ?>">

 

In the <input> this cuts off at the ' if I do value='' and the " if I do value ="" and at either if I just do value=

 

How do I get around this?

 

You need to escape the quote that would otherwise cause the string to terminate:

$var = "The length is 5' x 2\" and blah blah blah";

It is the input field, it's not actually a PHP related question - it's straight HTML.

 

Don't you just LOVE HTML? :)

 

By the way, here is a quick fix, use the HTML code for the double quotation:

$var = "The length is 5' x 2&#34; and blah blah";

It will output correctly for you and show up right, just a pain to work with.

 

EDIT:

" might work in place of &#34; and a bit easier to use.

To put characters that have meaning in HTML into form field value parameters, you need to convert the special characters to HTML entities so that they are not operated on by the browser when it renders the page - http://us3.php.net/htmlentities

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.