LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-07-2006, 10:48 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Rep: Reputation: 40
PHP: Read html file, diplay result


I've written a small php-function that reads a html-file one line at a time and display the result on screen. However, when trying to display a line like the the following, nothing happends (some browsers display something like \"...\" in a box):
<img src="images/image.jpg" width="388" height="307" alt="...">

How can I make php read the line and display it (echo it) just as if the browser was interpreting it?
 
Old 01-07-2006, 11:46 AM   #2
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
Look at the src attribute for your img tag. It's using a relative path, which means that the browser will interpret it as being relative to the directory where your PHP script is located. Since that path apparently isn't valid, you'll need to parse the line and change the value in the src attribute before echoing the line.
 
Old 01-07-2006, 12:54 PM   #3
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by AdaHacker
Look at the src attribute for your img tag. It's using a relative path, which means that the browser will interpret it as being relative to the directory where your PHP script is located. Since that path apparently isn't valid, you'll need to parse the line and change the value in the src attribute before echoing the line.
Thanks for the reply. But the path is correct, and the problem being that parsing quotes(") ,or what it is called, doesn't work. I'm sorry if I was unclear in my first post. Having quotes works when applied directly into the html code, but hot when php reads and print lines from an html source.
 
Old 01-07-2006, 01:08 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Do you mean that you want to send the following to the browser?

Code:
<img src="images/image.jpg" width="388" height="307" alt="...">
if so the following will work for you

PHP Code:
echo "<img src=\"images/image.jpg\" width=\"388\" height=\"307\" alt=\"...\">"
or

PHP Code:
$image "images/image.jpg";
$width 388;
$height 307;
$alt "...";
echo 
"<img src=\"$image\" width=\"$width\" height=\"$height\" alt=\"$alt\">"
graeme.
 
Old 01-07-2006, 01:11 PM   #5
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
I guess I'm not understanding what the problem is. What, exactly, is the difference between the HTML code you see in the HTML file itself and the HTML code that your PHP script sends to the browser?
 
Old 01-08-2006, 08:10 AM   #6
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by AdaHacker
I guess I'm not understanding what the problem is. What, exactly, is the difference between the HTML code you see in the HTML file itself and the HTML code that your PHP script sends to the browser?
Well, let me try and explain it again, this time making it understandable.

I have a file containing html-code. This html-code is full of quotes (") both surrounding html tag elements, and elsewhere in the text. Say I have the following line in my html code:

Code:
<a href="folder/file.php">This is an "example"</a>

This line is read by php and echoed to the screen (echo $line);

Now, the result is will be that every quote will be escaped by an backslash, which isn't what I want. I guess php does this by default because quotes are used in php syntax itself.

If I remove quotes in tag elements I eliminate one problem, leaving the quoutes in the text itself to be escaped. Therefore, I guess there must be some way of echoing lines regardless of whether the line contains quotes or not.

Was this more clear? Hope so. I'm not always very good at explaing things.
 
Old 01-08-2006, 08:43 AM   #7
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
Well, that clears it up.

You've fallen victim to magic_quotes_runtime. This is one of the more annoying "security features" of PHP which causes quotes in data from pretty much any external source (such as files and database queries) to be escaped. I guess the idea is to help protect the more clueless PHP programmers form SQL insertion attacks.

This can be turned off in your php.ini file. You can also disable it in a .htaccess file or even in code using:
PHP Code:
ini_set("magic_quotes_runtime""0"); 
 
Old 01-08-2006, 09:04 AM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You probably want to keep the magic quotes on (otherwise other programs may fail) but you can use the php function stripslashes() to remove them.

graeme.
 
Old 01-09-2006, 02:21 AM   #9
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
Great, thanks! I guess it would be best to try the stripslash-approach first (I don't want to cause problems on the server), so I'll have go at that.
 
Old 02-16-2006, 09:25 PM   #10
panicbox
LQ Newbie
 
Registered: Nov 2005
Location: Philippines
Distribution: Fedora Core 4, Debian
Posts: 21

Rep: Reputation: 15
hi!

is there anyway that i can have two images overlaying the other?

how? thanks!
 
Old 02-17-2006, 08:33 AM   #11
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Code:
<div style="background:url('images/img1.gif')"><img src="images/img2.gif" alt="" /></div>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
result.o file : impossible to read moutaye Linux - General 4 09-02-2005 04:22 AM
Can't get Kmail to diplay HTML emails Stevetgn Linux - Software 1 06-10-2005 06:40 PM
How can i read an write to a HTML or xml file using C alix123 Programming 1 11-24-2004 05:07 AM
Set up Apache to read php IN html code? WorldBuilder Linux - Networking 10 01-27-2004 12:16 PM
php in an .html file does not work NW Otter Linux - Software 4 09-23-2003 04:10 PM


All times are GMT -5. The time now is 09:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration