Displaying tabs and \'s from in HTML from MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
perimere
Forum Newbie
Posts: 3
Joined: Thu Apr 17, 2003 6:30 am
Location: London

Displaying tabs and \'s from in HTML from MySQL

Post by perimere »

Hi,

I'm pretty new to PHP so excuse the newbie-factor. I did search the forum prior to posting, but couldn't find a solution to this.

Basically I have a knowledge base configured on MySQL, and I'm using PHP pages to insert and display articles posted.

The problem is "\" and "tabs" are lost when the article is retrieved and displayed. I'm still trying to get my head around PHP syntax etc and I thought Egrep_replace might work, but I was hoping to find something akin to nl2br to make it easy ;-)

Thanks in advance for any suggestions.

Perimere :roll:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

don't exactly know what you want to do but maybe <pre>..</pre> will help

Code: Select all

<html><body>
<?php	echo "a\tb\\c"; ?>
<pre><?php	echo "a\tb\\c"; ?></pre>
</body></html>
perimere
Forum Newbie
Posts: 3
Joined: Thu Apr 17, 2003 6:30 am
Location: London

Feedback

Post by perimere »

volka,

Thanks for taking the time.

What I am trying to do (and I doubt I'm the first - so it must be easy?!!?) is get information entered into a form, which is then submitted into MySQL.

All that works fine. However when I query the information back from sql and display it in html certain characters, formatting is lost (i.e. Tab spacings and forward slashes).

Example:
For i = 1 to 100
<Imagine a tab spacing here> set target = "c:\test\path"
Next

Okay so the above is a VBS code snippet (sorry still learning PHP) that a user may enter into the form on my website. When it's stored in the database the formatting is still okay (I checked using MySQL tools)

However when I retrieve the data to display it in html the display looks like:
For i = 1 to 100
set target = "c:testpath"
Next

I was just wondering how everyone else gets around this issue? Is there an easy function to use in PHP, or is it a case of parsing the variable prior to storing it in MySQL?

Any suggestions would be greatly appreciated :-)

perimere
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Backslashes: could it be that text is NOT being escaped on the way into the database but IS being stripslashed on the way out?

I don't think ereg is the solution here.

(Actually, ereg probably isn't a solution for anything since the regex preg.. stuff is faster - and str_replace() faster still if you don't need the power of preg...)
perimere
Forum Newbie
Posts: 3
Joined: Thu Apr 17, 2003 6:30 am
Location: London

Ahhhh

Post by perimere »

McGruff,

okay you got me there ;-) I just read some doco on that and I think that should resolve the backslash issue.

*wonders if this will tackle tha tab issue also*

Thanks for the feedback.

Cheers

perimere :-)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

html <pre> tags will display tabs & other whitespace OK in the browser

glad to be of help
Post Reply