[thelist] PHP - RegExp & Array problems

Lachlan Cannon luminosity at members.evolt.org
Sun Jun 23 00:50:01 CDT 2002


\Beau Hartshorne\ said:

> 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\'))

Hmm.. yeah.

> 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?)

Ok. Basically, I have a db with all my stylesheets in it. This goes through
and sets the visual stylesheets to either alternate or normal stylesheets
depending on what people have selected as their preferred one (my PHP CSS
switcher). The trouble is this file is a directory below the public_html
level, and so it's not allowed to connect to the db, so stylearray.php just
walks through the db, and assembles an array with all the information and
returns it. That's what stylelist is. $prefstyle is the title of their
preferred stylesheet.

>
> 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.

Awesome, works a treat. Thanks a bunch.

> 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>?

Well, browsers are supposed to put them in automatically. You can then
adjust them to other types of quotes with CSS too. Take a gander at the
following: http://diveintomark.org/archives/2002/05/04.html#the_q_tag

Lach
_____________________________________
http://members.evolt.org/luminosity/
MSN: luminosity @ members.evolt.org
_____________________________________





More information about the thelist mailing list