[thelist] PHP - RegExp & Array problems

Beau Hartshorne beau at members.evolt.org
Sat Jun 22 20:55:01 CDT 2002


Hi Lach,

It looks like you've forgotten to escape your newlines and tabs. They
should be "\n" and "\t" instead of "n" and "t".

Code like this is hard to read:

($stylelist[$i]['title'] != $prefstyle &&
 $stylelist[$i]['media'] == 'screen')

You should use more brackets:

(($stylelist[$i]['title'] != $prefstyle) &&
 ($stylelist[$i]['media'] == 'screen'))

I don't really understand what you're trying to do with the rest of the
code. Could you explain it to me? And could you post the code with a
little more context? (Where is the $stylelist array introduced, and what
information does it hold?)

I'm no regular expression expert, but this code was provided in the php
manual as an ereg_replace example to find URLs:

$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
                     "<a href=\"\\0\">\\0</a>", $text);

I tested it, and it won't catch the period at of a URL.

Again, I'm no regular expression expert. I don't know how to search for
the quotes and replace them with <q> and </q>. BTW, is there a way to
get real (") quotation marks around anything contained in the <q> and
</q>?

Cheers,

Beau

> Ok, first of all, as is visible on my site (link at bottom), for some
reason
> the word "Array" is being injected into a variable by PHP. I have no
idea
> why. The code where the variable is used goes like this:
>
> $styles = '';
> for ($i=0; $i<count($stylelist); $i++) {
> 	if ($stylelist[$i]['title'] != $prefstyle &&
$stylelist[$i]['media']
> ==
> 'screen') {
> 		$styles .= "t".'<link rel="alternate stylesheet"
> href="/luminosity/style/'.$stylelist[$i]['name'].'.css"
> media="'.$stylelist[$i]['media'].'"
title="'.$stylelist[$i]['title'].'"
> type="text/css" />'."n";
> 	}
> 	else {
> 		$styles .= "t".'<link rel="stylesheet"
> href="/luminosity/style/'.$stylelist[$i]['name'].'.css"
> media="'.$stylelist[$i]['media'].'"
title="'.$stylelist[$i]['title'].'"
> type="text/css" />'."n";
> 	}
> }
>
> That's it, and somehow the word "Array" is appended to the start of
the
> string. Any idea why?
>
> Secondly, I'm having trouble with my regexp for selecting URLs. It
works
> fine as it is, however if there is a period at the end, for the end of
a
> sentence that is also selected as part of the URL. How do I change it
so
> that it will select any url it currently does except if the last
character
> is a period (and in that case select up to the period).
>
> The regexp I use currently is:
>
> $comment =
> eregi_replace('(http://(([A-Za-z0-9.-_])*)([A-Za-z0-9./-_])*)','<a
> href="\1">\1</a>',$comment);
>
> Also, while I'm at it, what would be a good regexp for selecting a
pair of
> double quotes inside a paragraph (seperated by line breaks), and
> transforming them into a <q> and </q> if it was indeed a pair inside
the one
> para?
>
> <tip type="Adjusting MySQL date values" author="Lachlan">
> If you need to adjust the date value automatically inserted into a
date
> field on your server to bring the date into your timezone use the
following
> code:
>
> NOW() + INTERVAL x HOUR
>
> Where x is the number of hours.
> </tip>
>
> Thanks,
> Lach
> _____________________________________
> http://members.evolt.org/luminosity/
> MSN: luminosity @ members.evolt.org
> _____________________________________
>
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !






More information about the thelist mailing list