Re: PHP tags within a link

This way won't work (single quote delimited strings are not parsed for 
variable references), correctly it would have to be:

<?PHP
print '<a href="/texis/master/search/mysite.html?q='
. $celebsearch . '">';
?>

or better even (assuming that $celebsearch is not yet URLencoded):

<?PHP
print '<a href="/texis/master/search/mysite.html?q='
. urlencode($celebsearch) . '">';
?>


Another alternative would be to pre-process the PHP3 file (before sending 
it to tidy) and replacing all occurences of <?PHP ... ?> with a placeholder 
string, storing the content of the PHP tags in an array and then 
post-processing tidy's output and inserting back the PHP codes.

In Perl, I would do that like this:

## pre-process:
# replace all <?PHP ... ?> blocks with a placeholder string
$i = 0;
while ($filecontent =~ m/(<\?PHP.*?\?>)/gsi) {
   $PHPStack[$i] = defined($1) ? $1 : "";
   $filecontent =~ s/<\?PHP.*?\?>/PHPStackPlaceHolder\[$i\]/si;
   $i++;
}

## post-process:
# replace all placeholder strings with the right <?PHP ... ?> blocks
for ($i = 0; $i <= scalar @PHPStack; $i++) {
   $tidyOutput =~ s/PHPStackPlaceHolder\[$i\]/$PHPStack[$i]/s;
}


At 19:19 24.11.2000 +0000, Daniel Biddle wrote:
>On Fri, 24 Nov 2000, Ian M. Evans wrote:
>
> > Just wondering how to handle the insertion of PHP variables or scripts that
> > occur within a link.
> >
> > For example:
> >
> > <a
> > href="http://digitalhit.master.com/texis/master/search/mysite.html?q=<?php
> > echo $celebsearch; ?>">
>[...]
> > Is there anything I can do to stop tidy touching the <?php and ?> within a
> > link? It leaves them alone properly outside a link.
>
>Don't do that then!
>
>Seriously, don't use php inside a tag, but replace the whole tag:
>
><?php echo '<a href="http://digitalhit.master.com/texis/master/search/'
>         . 'mysite.html?q=$celebsearch">'; ?>
>
>Of course this needs the end tag, and possibly the contents of the
>element, to also be generated by php, or tidy will complain about
>mismatched tags.
>
>
>hope this helps,
>--
>Daniel Biddle <deltab@osian.net>

--
Sebastian Lange
http://www.sl-chat.de/
Maybe the first chat site that validates as HTML
4.0 even though user input may contain HTML codes.

Courtesy to Dave Raggett's HTML Tidy:
http://www.w3.org/People/Raggett/tidy/

Tidy your documents ONLINE:
http://www.sl-chat.de/Tidy/

Received on Monday, 27 November 2000 04:10:05 UTC