473,785 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading "<?" from a php file

aa
I am trying to read a.php file from another PHP file using fgets() and
display its contents. As a.php starts with <? the browser IE6 does not show
anything, although I can see all the contents in View-Source.

I tried to skip the line with <? using the following code:

@ $fp=fopen("a.ph p","r");
while (!feof($fp))
{
$line=fgets($fp );
if (!$line=="<?")
{
echo $line;
}
else
{
echo "w";
}
However it keeps outputting "w" for every line of a.php.
This does not change even is I reverse the condition to if (!$line=="<?")
as if whatever is returened by fgets($fp) cannot be compared to "<?".
I tried to add the end of the line to the pattern (!$line=="<?\n" ) or
($line=="<?\n") - same result.

What is that I am doing wrong?

Jul 17 '05 #1
12 2282

Your first line, which opens the file, suppresses any error message and
you don't test for any errors.

I bet you this $ sign that if you remove the '@' you will see an error
message. Tell us what the error message is and we can help.

---
Steve

Jul 17 '05 #2
aa wrote:
I am trying to read a.php file from another PHP file using fgets() and
display its contents. As a.php starts with <? the browser IE6 does not
show anything, although I can see all the contents in View-Source.

I tried to skip the line with <? using the following code:

@ $fp=fopen("a.ph p","r");
while (!feof($fp))
{
$line=fgets($fp );
if (!$line=="<?")
{
echo $line;
}
else
{
echo "w";
}
However it keeps outputting "w" for every line of a.php.
This does not change even is I reverse the condition to if (!$line=="<?")
as if whatever is returened by fgets($fp) cannot be compared to "<?".
I tried to add the end of the line to the pattern (!$line=="<?\n" ) or
($line=="<?\n") - same result.

What is that I am doing wrong?


Hi,

I think you better use htmlentities. That function was written to display
'difficult' pieces of text into a HMTL page.
I suspect that if you just drop your <? piece and use html_entities, you get
what you are looking for.

Check this:

http://nl3.php.net/manual/en/function.htmlentities.php
Regards,
Erwin Moller
Jul 17 '05 #3
How about using
<?php
print htmlentities( join('', file('a.php')) );
?>

This reads the file and escapes all the HTML entities in your file and
makes the output browser-ready.

For a complete script (and as well as concrete idea), please take a
look at http://www.php.net/source.php?url=/source.php

(Source of PHP.net pages can be seen by click the view source link at
the bottom of each page... above link is the source of source.php that
does the job)

Thanks,
--Kartic

Jul 17 '05 #4
.oO(aa)
I am trying to read a.php file from another PHP file using fgets() and
display its contents. As a.php starts with <? the browser IE6 does not show
anything, although I can see all the contents in View-Source.
htmlspecialchar s() is your friend.

http://www.php.net/htmlspecialchars
I tried to skip the line with <? using the following code:
Not necessary.
@ $fp=fopen("a.ph p","r");
while (!feof($fp))
No error handling? What if the file is not readable?
$line=fgets($fp );


You might also want to have a look at file() or file_get_conten ts().

http://www.php.net/file
http://www.php.net/file_get_contents

HTH
Micha
Jul 17 '05 #5
Don't reinvent the wheel. Use show_source().
http://www.php.net/show_source/

Jul 17 '05 #6
aa
Thanks for offering other options.
However I would like to understand what is wrong with the one I am using?
The litaruture does not say that fgets() is not suatable for reading
characters like "<" which migh happen in any text file.

"Michael Fesser" <ne*****@gmx.ne t> wrote in message
news:58******** *************** *********@4ax.c om...
.oO(aa)
I am trying to read a.php file from another PHP file using fgets() and
display its contents. As a.php starts with <? the browser IE6 does not showanything, although I can see all the contents in View-Source.


htmlspecialchar s() is your friend.

http://www.php.net/htmlspecialchars
I tried to skip the line with <? using the following code:


Not necessary.
@ $fp=fopen("a.ph p","r");
while (!feof($fp))


No error handling? What if the file is not readable?
$line=fgets($fp );


You might also want to have a look at file() or file_get_conten ts().

http://www.php.net/file
http://www.php.net/file_get_contents

HTH
Micha

Jul 17 '05 #7
aa wrote:
Thanks for offering other options.
However I would like to understand what is wrong with the one I am using?
The litaruture does not say that fgets() is not suatable for reading
characters like "<" which migh happen in any text file.
The problem is this line:
if (!$line=="<?")


You're basically saying "if $line is zero equals <?", which always fails
since $line isn't zero (nor would if equal <? if it ever was zero).

Try this instead: if ($line != "<?")

That one says "if $line isn't <?" which is exactly what you're trying to
say.
Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Jul 17 '05 #8
In comp.lang.php aa <aa@virgin.ne t> wrote:
Thanks for offering other options.
However I would like to understand what is wrong with the one I am using?
The litaruture does not say that fgets() is not suatable for reading
characters like "<" which migh happen in any text file.


Check thr fgets function: on a newline (which is included in the return
value)

Seeing that you post TOFU style with broken quotes, I guess you are
running on the windows platform where a newline is not \n. So either
trim the read line or (better) use strpos.

FUP to comp.lang.php
Jul 17 '05 #9
aa
Thanks, Roy, I felt I was missing something fundamental in PHP syntax.
Will you please explain how
if(!$line=="<?" )
is interpreted by PHP as
"if $line is zero equals <?" ? I.e. if(!$line= (0=="<?"))

Where zero is implied in (!$line=="<?") ?

"Roy W. Andersen" <ro******@netgo th.org> wrote in message
news:34******** *****@individua l.net...
aa wrote:
Thanks for offering other options.
However I would like to understand what is wrong with the one I am using? The litaruture does not say that fgets() is not suatable for reading
characters like "<" which migh happen in any text file.


The problem is this line:
> if (!$line=="<?")


You're basically saying "if $line is zero equals <?", which always fails
since $line isn't zero (nor would if equal <? if it ever was zero).

Try this instead: if ($line != "<?")

That one says "if $line isn't <?" which is exactly what you're trying to
say.
Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2801
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String relationalOp) { List list = new ArrayList();
1
6906
by: Serguei | last post by:
Dear Experts, I try to use a < character as a part of an attribute value in the following way: ......... <ConditionalStatement seqNumber="5" relationalOp="S<"/> ......... If I try to use the Internet Explorer browser to show a file with this line, it failed with the error message:
1
6828
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
7
2090
by: Diandian Zhang | last post by:
Does anyone have an idea, how to do it? Thanks in advance!
8
2427
by: Tom | last post by:
Hi I have an aspx page which has javascript to configure xmldata. I added breakpoint to the button method. When I click submit button, it did not go to those breakpoint and show the following error System.Web.HttpRequestValidationException (0x80004005) Detect the potential danger of Request.Form value from client side (idHidxml="<recordset><record><...") System.Web.HttpRequest.ValidateString(String s, String valueName, String...
4
2720
by: Don Wash | last post by:
Hi All! I'm getting the following Error: No DLLs has been compiled yet and nothing in the \bin directory. So it is not the versioning problem or anything like that. And here are the source of the files...
2
6859
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node as a value. Check out the following problem. I want to convert the value in <WpDatesXml> node to have a valid "<" and ">" instead of &lt or &gt format so that I can use this xml for another use. Please help! <NewDataSet> <Table1>
3
2183
by: Steven.Xu | last post by:
hi everybody, i am useing some classes which in System.Xml to deal with xml document. what can i do if the document include "<" or ">"? Thanks.
3
2186
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to understand thanks a lot and sorry for inconvenience..
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.