Preg_match - strange output?

software development


I’m trying to extract pieces from a string, but the output I get on DreamHost is different than expected. Any ideas?


1st part (extracting URL):

Why the backslash???

2nd part (extracting width value):

no output.

there should be plus signs after each [] group but the forum won’t show them.

Please help! :slight_smile:

Just to clarify, these expressions WORK perfectly on another server.


Why not try the approach of parsing the attributes out, then the values.


preg_match_all(’/\s([A-Za-z][0-9A-Za-z_:.-])="([^"])"/i’, $html, $attributes, PREG_SET_ORDER);

echo “Attributes:

echo “

foreach ($attributes as $attribute) {
$name = $attribute[1];
$value = $attribute[2];
if (strcasecmp(‘SRC’, $name) == 0) {
$stringURL = $value;
if (strcasecmp(‘WIDTH’, $name) == 0) {
$stringWidth = $value;

echo “URL: $stringURL
Width: $stringWidth\n”;

php?>[/code] :cool: -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


Wow, wish I knew about that :slight_smile:

Problem is, it works on my system perfectly, but not on Dreamhost. All I get for output is:

URL: Array
Width: Array

It’s as if Dreamhost treats string’s differently than PHP. Is there a difference between PHP_MOD and PHP_CGI that could cause this?

if I use print_r I get

[quote]Array ( [0] =>\ [1] => [2] => [3] =>\ )
Array ( ) [/quote]

Those 's are still there! Grr.


Turns out if I use mod_php it causes all kinds of issues. As soon as I used
AddHandler php5-cgi .html
instead of ForceType
in my .htaccess file
it works properly now!

Wohoo :slight_smile:

Thanks for your help, that little bit of script will come in handy later.