Jump to content

[SOLVED] Display / edit string trap


patrickm

Recommended Posts

On a website, I have written a piece of code which allows editing of product specifications. The data is pulled from a MySQL database and displayed in an form-like page with <input> and <textarea> elements.

 

But I can't seem to find a good workaround for the following problem:

 

echo "<p><b>Omschrijving</b>";
echo "<br><input value=\"$dump_gegevens->omschrijving\" type=\"text\" size=\"60\" name=\"form_omschrijving\">";
echo "</p>";

Displays an input field which is filled already by the proper data (in the above example called "omschrijving").

 

Some of the products have a description in this field with " in it. If I enter the following string (placed between [ ] for clearity) [blah blah blah ("whatever")] if will only parse the input until the first " (obvious).

 

So, if I use \", it won't work either (with <input>). The only way around it is to use &#034; or double '.

 

If I use &#034; I end up with a new problem: the next time the specs of this product gets edited, the <input> field shows the correct html/php output and the &#034; get replaced by " (and saving it will cause this field to be truncated after the first (displayed) ").

 

Question: how can I display the content of a string ($whatever->content) in such a way that the content is listed "as it is" (like < pre > in html) and &#034; would become visible?

Link to comment
Share on other sites

htmlentities() and html_entity_decode()

 

http://www.php.net/htmlentities

 

http://www.php.net/manual/en/function.html-entity-decode.php

 

When you use $_POST to read the form use something like this:

<?php
  $var=htmlentities($_POST['formvar'],ENT_QUOTES);
?>

 

When you want to add the data back into a form use something like this:

<input type="text" name="formvar" value="<?=html_entity_decode($var,ENT_QUOTES)?>" />

Link to comment
Share on other sites

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.