Pretty source AND html-output (page source) ?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
mygind
Forum Newbie
Posts: 3
Joined: Mon Mar 23, 2009 10:03 am

Pretty source AND html-output (page source) ?

Post by mygind »

Dear all,

I was wondering if anyone could point me to a place going through the subject making both php-source and the html-output (page source).

Lets say I have a these functions:
printCell($contents){
return "<td>" . $contents . "<td>";
}

printLink($contents){
return "<a>" . $contents . "</a>";
}

Performing this action
echo printCell(printLink("Link"));

Results in an output that looks
<td><a>Link</a><td>

I would like it to print something loke this
<td>
[tab]<a>Link</a>
</td>

This would also be ok
<td>
[tab]<a>
[tab][tab]Link
[tab]</a>
</td>

I wonder if this is possible in some easy way?

I thought about using a $indent variable - but somehow it feels awkward to write:
printMainTable($indent){
return
$indent . "<table>" . "\n" .
$indent . "\t <tr>" . "\n" .
$indent . "\t\t <td>Title</td>" . "\n" .
$indent . "\t </tr>" . "\n" .
$indent . "</table>";
}
And the source suddenly turns into code which I would like to prevent.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Pretty source AND html-output (page source) ?

Post by jayshields »

If I understand you correctly you could just use CSS to style your elements. Something like the margin-left attribute should do the trick, but I don't know how these source formatters work though, so maybe just look into their CSS.
mygind
Forum Newbie
Posts: 3
Joined: Mon Mar 23, 2009 10:03 am

Re: Pretty source AND html-output (page source) ?

Post by mygind »

The css would change how the text is formatted on output from html to what you see (html->see), right?

What I want is my text to look pretty when you read page source (in firefox rightclick and press view page source) that is formatting the output from php to html (php->html)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Pretty source AND html-output (page source) ?

Post by jayshields »

What's the point in that? On topic, you can use \t and \n for tabs and new lines, respectively.
mygind
Forum Newbie
Posts: 3
Joined: Mon Mar 23, 2009 10:03 am

Re: Pretty source AND html-output (page source) ?

Post by mygind »

It makes it easier to find whatever you might look for in the html source - say a link hidden behind a picture etc.
And then it looks as if it was written by hand as in good old times ;)

To me it seems right at least...
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Pretty source AND html-output (page source) ?

Post by jayshields »

Well yeah, try using "\t" - in double quotes.

...but I still don't know why you'd go out of your way to make your HTML source look nice. I agree that by principle you should try to make it look nice, but when it requires extra work, just leave it - it doesn't really matter as long as your comfortable with the formatting in the development view. If anyone really wants to inspect your source they can just paste it into their favourite editor.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Pretty source AND html-output (page source) ?

Post by php_east »

readablity perhaps, i do sometimes wish i do the same for my html output when problems arises.

anyways, try this function, maybe it will suit you, as you need not worry about formating when you are forming the html proper.

Code: Select all

$a='<td><a>Link</a><td>';
print_r( implode('>'.chr(13),explode('>',$a)) );
 
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Pretty source AND html-output (page source) ?

Post by JAB Creations »

If you want line breaks to make your (X)HTML output humanly readable then use \n.

In example...

Code: Select all

<?php
echo '<div><p>some text here</p></div>'."\n";
?>
Post Reply