View Source Function

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
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

View Source Function

Post by icesolid »

I have a small scripts section on my site, and I show the source code for each script right out of the database onto the script page using the hightlight_string(); function.

The only thing that sucks is that some of the scripts push out my tables on my site and make it look real <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>. I have also tried the show_source(); function, and that does the exact same thing (obviously).

So I guess what I am asking is if there is anyway to make it so that when the source code is printed out, it does not override my tables and push them way out.
Zmodem
Forum Commoner
Posts: 84
Joined: Thu Apr 18, 2002 3:59 pm

Post by Zmodem »

I don't have any experience with this function, but would it help if you specified specific lengths for your table, rather than using a percentage?

Like this:

<table width="300">

instead of:

<table width="50%">
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

I never use percents

Post by icesolid »

I never use percents on my current design. So that can not be it.

Got any other ideas.

:idea:
Junk Guy
Forum Newbie
Posts: 9
Joined: Thu Jun 20, 2002 11:55 am

Post by Junk Guy »

Wrap the output with
<PRE>...</PRE>
?
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

it's very strange, maybe it's an issue with having so many nested tables? I've tried to follow them in the source but I couldn't see why they seem to ignore your 'width='?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Does highlight_string() not line wrap? (I can't seem to get on php.net to find out). If it doesn't that's probably why it's breaking your tables.

Mac
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

found it!
in
Title: Edit MySQL Records
Category: Databases
Date: Saturday, April 6, 2002
on line 57 of the output you have a great big long mysql query
$result = mysql_query("UPDATE users SET name='$name',email='$email',phone='$phone' WHERE id=$id");
But there are no spaces in it so it can't word wrap, so it forces the table to be to wide. If you put a space in yourself at the appropriate point it will wrap ok. It might have been easier to debug without all the font tags, a bit of CSS would save you a lot of coding. :wink:
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Still no help

Post by icesolid »

No, none of your ideas have worked. The <pre></pre> thing just makes all the code print out without any wrapping, so its worse.

Any one else with an idea? :?:

P.S. e+ I am not talking about the script code in my database. I am talking about when I go to print out that code, how do I make it so it will not push out my tables.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

If you put spaces after the commas in your code it will work fine (or at least for the example I found). It's still perfectly acceptable code but it won't force the cell to be so wide. Because you have one VERY long string of letters the cell can't stay within the width you have told it to be so it's overiding your width command and making the cell as wide as the longest string of letters (the sql query). Once you put spaces in after your commas it will be able to wrap the text within the cell and not force it to resize. I know this works because I have done it to the source I captured from your page.
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

actually i believe the problem to be with the PHP functions. they convert all spaces to &nbsp;. Therefore all lines become incredibly long strings (with no spaces)... the only place for the function to wrap is at the end of the line. try looking at the source that either PHP function outputs...you should see what i'm talking about.

as far as a way around this? write a wrapper that converts the &nbsp; back to spaces? very inefficient and dirty, but it would work.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

I'm not lying to you all it really does work if you put a space after the commas, viewsource edit it and see for yourselves. With regards the non breaking spaces it doesn't matter because the browser interprets these as spaces and is happy to wrap them. :roll:
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

i'm assuming you mean adding spaces after the commas in his mysql call? that may work fine for that line, but what about any other long ones. i too have a 'viewsource' page on my site, and it simply will not break a block of text to wrap it. it will see the space between an HTML tag and it's attribute, but not with blocks of text... they are all converted to &nbsp; and won't budge.

<edit>
ok, well i found out why it's not working for me....not sure if it will apply to the issue that started this thread. i am echo()ing out rather large strings, and it is the text blocks in these that won't break. if you "?>" out of your PHP code, do your large blocks of pure HTML, and then "<?php" back in, it wraps
</edit>
Post Reply