Re: Anyone have a tool/script to convert <? to <?php (but not <?=)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 14, 2014 at 2:21 PM, Daevid Vincent <daevid@xxxxxxxxxx> wrote:

> Try it...
>
> <?php $foo='bar'; ?>
> <?= $foo ?>
> <?=$foo?>
> <?echo 'i told you so';?>
> <?phpecho 'this one fails';?>
>
> The ONLY one that gives a parser error is the LAST one where yes, a space
> is required after a <?php
>
> That is NOT the case for <? or <?=
>
> > -----Original Message-----
> > From: Aziz Saleh [mailto:azizsaleh@xxxxxxxxx]
> > Sent: Friday, February 14, 2014 10:54 AM
> > To: Daevid Vincent
> > Cc: php-general@xxxxxxxxxxxxx
> > Subject: Re:  Anyone have a tool/script to convert <? to <?php (but
> not
> > <?=)
> >
> > What I posted (and all the others) would work, replacing all instances of
> > "<? " (notice the space) with "<?php " should work, it will leave all
> > existing  <?= and <?php alone (since having a space after ? and before
> > =/php would produce a parser error.
> >
> > Not sure why you are saying that spaces are irrelevant thou.
> >
> >
> > On Fri, Feb 14, 2014 at 1:34 PM, Daevid Vincent <daevid@xxxxxxxxxx>
> wrote:
> >
> > > *sigh*
> > >
> > > <?=$foo?> is perfectly valid so is <?=$foo;?> or any combination WITH
> > > SPACES OR NOT.
> > > If this were trivial, I wouldn't have asked the list. I've been coding
> PHP
> > > since 1996. ;-)
> > >
> > > So if you have <? you have to make sure it doesn't have a '=' after the
> > > '?' to convert to '<?php'
> > >
> > > Spaces are irrelevant and can NOT be relied upon as a unique feature.
> > >
> > > > -----Original Message-----
> > > > From: Daevid Vincent [mailto:daevid@xxxxxxxxxx]
> > > > Sent: Wednesday, February 12, 2014 2:57 PM
> > > > To: php-general@xxxxxxxxxxxxx
> > > > Subject: RE:  Anyone have a tool/script to convert <? to <?php
> (but
> > > not
> > > > <?=)
> > > >
> > > > Thanks guys for the replies so far, however, if it were a simple
> search
> > > and
> > > > replace I wouldn't have to ask ;-)
> > > >
> > > > The trick is that "<?=" is valid and legal and I want to keep those.
> I
> > > only
> > > > want to change if they are specifically "<?"
> > > >
> > > > Maybe there is some regex guru out there that knows the magic
> > > incantation.
> > > >
> > > > Related, for extra credit it drives me bonkers to see this:
> > > >
> > > >       Hello <?= $username; ?>
> > > >
> > > > Note the end semicolon on the variable. I'd want to strip all those
> off
> > > too,
> > > > but that is also not a trivial task if you think about it as it can
> only
> > > be
> > > > removed if proceeded with <?=
> > > >
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I agree with the list you posted. However, if you try:

<? =$test;?>
or
<? php echo $test;?>

Both will parse out.

Which brings me back to the original regex:

'<? ' -> will match:

'<? ...'
and not any of the cases you posted, including:

'<?php'
or
'<?='

Then again, I didn't have my morning tea and could just be thinking of
something different!

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux