Jump to content

html text into textarea field, then stored into a db


bradkenyon

Recommended Posts

I ran into this problem before, but I think its a little harrier this time.

 

An example would be putting this into a textarea field:

 

<a href="http://www.yahoo.com">yahoo.com</a>

 

Then when I display it to update it, it displays as: yahoo.com</a>"><a href="http://www.yahoo.com">yahoo.com</a>

 

I want it to display as what I typed it in, then when it displays in the news page, to display as yahoo.com, as a link.

 

Any help would be appreciated, as I have looked into htmlentities, htmlspecialchars_decode, and htmlspecialchars.

Link to comment
Share on other sites

Dont know if im getting this right, but what im understanding is u want the url to be parsed and instead of showing just a text, show it as an url. U could have a regular expression who searches for "www.something.com" or "something.com" and replace it with

<a href="http://www.something.com/">www.something.com</a>

Link to comment
Share on other sites

I'll type in the a href = into the textarea as well, so I want it to display <a href="http://www.yahoo.com">yahoo.com</a> in the update text area form, and a linked yahoo.com within the site side of the news item.

 

so when the user views it on the website, they will see yahoo.com as a linked item they can click to go to yahoo.com, and when you go to the backend to update the news item, it will display as <a href="http://www.yahoo.com">yahoo.com</a>, so i want the site side code to translate the <a href=""> and </a> to a link.

Link to comment
Share on other sites

Writing html elements in a textarea, unless u used htmlentities(), theyll show as html elements. I think i get what u want to achieve by replacing the html link with just a website.com, but it would be technically overwhelming. Basically:

 

- Retrieve the text from the database

- Run a regex to remove html anchor tags

- Display the data to the input field

- When the form submits, run again a regex to add html anchor tags to the text, wherever it finds "website.com"

- Update the database

 

If this is for a client or someone who isnt technically profficient, id suggest using bbcode similiar to those used in forums. So a link would be:

 

[url=http://www.yahoo.com]Yahoo[/url]

 

You could only parse the bbcode on the showing part, but leave it in the backend, as it is pretty easy to understand. Im sure there are pretty good tutorials out there to achieve this.

Link to comment
Share on other sites

all i want to do is be able to type in html code as well as plain text and for the html code to display as it should.

 

so for an image, i want <img src="/images/image.jpg"> to display the image in the news item, and when i go to edit that news item, it shows the html code.

 

that is all.

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.