473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

commenting ?>

I cant think in any reason why this code fails...

Commented line shuldn't be completely ignored by the parser?

<?php

// ?whatever

ehco 'bla bla';

?>
In the real case, I'm having problems commenting out regex expressions
such as

$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

While this doesn't work:
// $res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

The following seems to be treated as expected

/*
$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);
*/

Again, I can't see the reason of that parser's behavior...

regards- julian

Jul 7 '06 #1
6 1266
*** julian_m escribió/wrote (7 Jul 2006 11:35:08 -0700):
I cant think in any reason why this code fails...

Commented line shuldn't be completely ignored by the parser?

<?php

// ?whatever
According to manual:

The "one-line" comment styles only comment to the end of the line or the
current block of PHP code, whichever comes first. This means that HTML code
after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
returns to HTML mode, and // or # cannot influence that.

It sounds like the logical option to me.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 7 '06 #2
Alvaro G. Vicario wrote:
*** julian_m escribió/wrote (7 Jul 2006 11:35:08 -0700):
I cant think in any reason why this code fails...

Commented line shuldn't be completely ignored by the parser?

<?php

// ?whatever

According to manual:

The "one-line" comment styles only comment to the end of the line or the
current block of PHP code, whichever comes first. This means that HTML code
after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
returns to HTML mode, and // or # cannot influence that.

It sounds like the logical option to me.
I didn't know that, now I understand how it works, although IMO, the
line I commented was not de end of the current block of PHP:

//$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

Note that ?is a string there.

regards - julian

Jul 7 '06 #3
On 7 Jul 2006 13:02:11 -0700, "julian_m" <ju***********@gmail.comwrote:
>Alvaro G. Vicario wrote:
>According to manual:

The "one-line" comment styles only comment to the end of the line or the
current block of PHP code, whichever comes first. This means that HTML code
after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
returns to HTML mode, and // or # cannot influence that.

It sounds like the logical option to me.

I didn't know that, now I understand how it works, although IMO, the
line I commented was not de end of the current block of PHP:

//$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

Note that ?is a string there.
Ah, but it isn't in a string, because it's in a comment.

(Sounds circular, but actually it's not).

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 7 '06 #4

Andy Hassall wrote:
On 7 Jul 2006 13:02:11 -0700, "julian_m" <ju***********@gmail.comwrote:
Alvaro G. Vicario wrote:
According to manual:

The "one-line" comment styles only comment to the end of the line or the
current block of PHP code, whichever comes first. This means that HTML code
after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
returns to HTML mode, and // or # cannot influence that.

It sounds like the logical option to me.
I didn't know that, now I understand how it works, although IMO, the
line I commented was not de end of the current block of PHP:

//$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

Note that ?is a string there.

Ah, but it isn't in a string, because it's in a comment.

(Sounds circular, but actually it's not).
Right.
Even though someone could think "hey dude, just comment with /* */ and
go ahead". there are situations, dealing with regex, where it wouldn't
work. For instance:

/*
preg_replace('#(<\s*span\s*>\s*<\s*/\s*span\s*>|<\?xml\s*:\s*namespace.*?>|<\s*/?\s*o\s*:\s*p\s*>)#si','',...)
*/

It's really annoying isn't it?

regards - julian

Jul 7 '06 #5
On 7 Jul 2006 13:26:45 -0700, "julian_m" <ju***********@gmail.comwrote:
>For instance:

/*
preg_replace('#(<\s*span\s*>\s*<\s*/\s*span\s*>|<\?xml\s*:\s*namespace.*?>|<\s*/?\s*o\s*:\s*p\s*>)#si','',...)
*/

It's really annoying isn't it?
Yep, nasty.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 7 '06 #6
julian_m (ju***********@gmail.com) wrote:

: Andy Hassall wrote:
: On 7 Jul 2006 13:02:11 -0700, "julian_m" <ju***********@gmail.comwrote:
: >
: Alvaro G. Vicario wrote:
:
: According to manual:
: >
: The "one-line" comment styles only comment to the end of the line or the
: current block of PHP code, whichever comes first. This means that HTML code
: after // ... ?or # ... ?WILL be printed: ?breaks out of PHP mode and
: returns to HTML mode, and // or # cannot influence that.
: >
: It sounds like the logical option to me.
:
: I didn't know that, now I understand how it works, although IMO, the
: line I commented was not de end of the current block of PHP:
:
: //$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?>#si', '<\1>',$str);

One solution is to split the string into pieces to break up the characters
and then concat the pieces.
$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?' . '>#si', '<\1>',$str);
^^^^^^

Or you can try to escape one or more of the characters to change the
string without changing its value. I'm not sure off hand if the php escape
works this way. What you want is to escape the character, which for
many characters is simply gives you the character itself (in some
languages, maybe in php).
$res= preg_replace('#<\s*(p|span|li|ul|ol)\s+.*?\>#si', '<\1>',$str);
^

Jul 7 '06 #7

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

Similar topics

1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
46
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is...
4
by: Ron McNulty | last post by:
Often when testing an app, I want to temporarily comment out sections of the App.config file. Is there any way to do this? Regards Ron
3
by: Naveen Mukkelli | last post by:
Hi All, I'm trying to create XML commenting for my code using XML commenting feature for the first time. I'm using VS.NET 2003 and C#. I'v tried the following way. Step 1: set the file name...
18
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an...
8
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments......
2
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any...
1
by: Wijaya Edward | last post by:
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0
100
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.