[thelist] PHP regex for catching text between "<?php" and "?>"

martin.p.burns at uk.pwcglobal.com martin.p.burns at uk.pwcglobal.com
Mon Jun 11 10:43:32 CDT 2001


Memo from Martin P Burns of PricewaterhouseCoopers

-------------------- Start of message text --------------------

Dunno about PHP, but Perl would be able to return everything before
the found string in the line as $` and everything after it as $'

And of course $1 $2 $3 for 'The first thing found matching the regexp',
'the second thing found' etc

Cheers
Martin





Please respond to thelist at lists.evolt.org

Sent by:  thelist-admin at lists.evolt.org

To:   "'thelist at lists.evolt.org'" <thelist at lists.evolt.org>
cc:


Subject:  [thelist] PHP regex for catching text between "<?php" and "?>"


Hi list,

Here's my current mission: Using PHP, find all occurrences of a string that
don't fall between "<?php" and "?>".

Example: Given the string "hello <?php there ?> world <?php foo ?>",
generate an array with element 0 as "hello" and element 1 as "world".

I'm fairly sure that I need to use preg_match (www.php.net/preg-match) to
return my array, the bit I'm having problems with is forming the regex
properly. Not being much good in this department doesn't help :-)

Any kindly regex gurus feel like demonstrating their wizardry and giving me
a pointer?


--------------------- End of message text --------------------

The principal place of business of PricewaterhouseCoopers and its associate
partnerships is 1 Embankment Place, London WC2N 6NN where lists of the
partners' names are available for inspection. All partners in the associate
partnerships are authorised to conduct business as agents of, and all
contracts for services to clients are with, PricewaterhouseCoopers. The UK
firm of PricewaterhouseCoopers is authorised by the Institute of Chartered
Accountants in England and Wales to carry on investment business.
PricewaterhouseCoopers is a member of the world-wide
PricewaterhouseCoopers organisation.
----------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material.  Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.   If you received
this in error, please contact the sender and delete the material from any
computer.





More information about the thelist mailing list