473,799 Members | 3,121 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
12 2283
aa wrote:
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=="<?") ?


Putting an exclamation-mark in front of a variable like that will test
the value of the variable. I said zero, but I guess "false" would be
more appropriate. I didn't mean the number 0, but zero as in nothing,
none, null, nada - call it what you like, just be aware that PHP will
probably want to call it false ;)

if (!$test) {
do_stuff();
}

In this case, do_stuff() will be called if $test is false, meaning if
$test is not set, if it contains the value 0, if it's set to null/false,
or if it contains an empty string (e.g. '', or "" if you prefer).

if (!$test == "some string") {
do_stuff();
}

In this case, do_stuff() will be called if $test is false and equal to
"some string", which by it's very definition isn't false - "some string"
can only be false if it's "", in which case it's no longer "some
string", and there it goes around and around until we get dizzy and give
up - PHP is smarter than us, so it just says "this won't work" and moves
on. The statement will never evaluate to true, and do_stuff() will never
happen.

Basically, just keep it simple. Ask the question in plain english, and
then translate it into PHP code. If you want to ask if $a equals $b,
then ask if $a == $b. If you want to ask if $a doesn't equal $b, then
ask if $a != $b. If you want to ask if $a is false, then you can either
ask if !$a, or if $a == false.

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 #11
"aa" <aa@virgin.ne t> wrote in message
news:41******** *************** @ptn-nntp-reader02.plus.n et...
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.


He didn't really state that clearly. He meant "is equal to" rather than
"equals".

This:
if(!$line == "<?")

Equates to:
if( !($line) == "<?")

As the '!' has higher precedence than the '=='.

So, either use:
if($line != "<?")

Or use:
if(! ($line == "<?"))

(the former is better).

-Noah
Jul 17 '05 #12
aa
Thank you both, now I see where my error was.
Jul 17 '05 #13

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
6829
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
7
2091
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
2723
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
6862
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
2187
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
10470
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
10247
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
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
7561
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
6803
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
5459
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
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2935
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.