Page 1 of 1

Displaying tabs and \'s from in HTML from MySQL

Posted: Thu Apr 17, 2003 6:30 am
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:

Posted: Thu Apr 17, 2003 7:43 am
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>

Feedback

Posted: Tue Apr 22, 2003 6:40 am
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

Posted: Tue Apr 22, 2003 6:54 am
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...)

Ahhhh

Posted: Tue Apr 22, 2003 7:46 am
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 :-)

Posted: Tue Apr 22, 2003 7:50 am
by McGruff
html <pre> tags will display tabs & other whitespace OK in the browser

glad to be of help