The Naked Truth

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
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

The Naked Truth

Post by harrison »

Hi, I am debugging my application and i want to display my HTML str in raw after I displayed it right.
What I mean is:
1. Display the HTML str I get from some class method, DisplayPage()
2. Debug the page by displaying the raw HTML.
Any idea?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I'm not entirely sure what your after. Here's a guess.
<pre></pre>
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

Post by harrison »

No, <pre> is for formatting text. I want to display the string together with HTML tags in it.
Sorry if i made you confused.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

by replacing

<
>
&
"


with

<
>
&
&nbsp;
"


(hope it helps)
Last edited by dethron on Thu Jun 23, 2005 10:00 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

depending how your script is setup, if you compile all your output into a string and apply the proper formatting -- much like a templating engine you could simply run your final output through htmlentities().

Now if you have been echo'ing out your output through the processing of your script, you could create a function that uses ob_get_contents() and grab any output sent to the browser, apply htmlentities and output the newly formatted html.
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

Post by harrison »

Wow, dethron. I never think about that before. :oops: I was expecting for a function but you got it right. Thanks.
Edited: I will try what jcart said.
Last edited by harrison on Thu Jun 23, 2005 10:04 pm, edited 1 time in total.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

your welcome, and now i am checking htmlentities() as Jcart pointed out. :)

Code: Select all

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);

// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

Post by harrison »

htmlentities() is perfect! I just need to use it with <PRE> because it loses its fomatting.

Code: Select all

function RawHTML($str){
	return '<br><b>Raw HTML</b><hr><pre>'.htmlentities($str).'</pre>';
}
Thank you all.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Why not using something like codebeautifier?
Or just put the plain html into a textarea-tag

djot
-
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Sounds like a good ideo but i only need it for HTML debugging purpose.
Thank you all.
Post Reply