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.
Pretty source AND html-output (page source) ?
Moderator: General Moderators
- 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) ?
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.
Re: Pretty source AND html-output (page source) ?
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)
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)
- 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) ?
What's the point in that? On topic, you can use \t and \n for tabs and new lines, respectively.
Re: Pretty source AND html-output (page source) ?
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...
And then it looks as if it was written by hand as in good old times
To me it seems right at least...
- 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) ?
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.
...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.
Re: Pretty source AND html-output (page source) ?
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.
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)) );
- 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) ?
If you want line breaks to make your (X)HTML output humanly readable then use \n.
In example...
In example...
Code: Select all
<?php
echo '<div><p>some text here</p></div>'."\n";
?>