Forum Moderators: coopster

Message Too Old, No Replies

Problem inserting variable in eregi_replace string

         

The Cricketer

3:34 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



MY PROBLEM:
I begin by retrieving these three fields from my database:

$storytext = $story['FIELD1']
$picture2 = $story['FIELD2']
$picture3 = $story['FIELD3']

//where $story['FIELD2'] = hello.jpg
//and $story['FIELD3'] = dog.jpg
---------------------------------------
I then use the code below to replace the FIELD1 text: 2 with
<div class="picture"><img src="/imagescripts/phpThumb.php?src=/images/hello.jpg&w=200"></div>

(where <b>2</b> is $picture2)
---------------------------------------
Here's how I attempt it:

function encode($str) {
$str = strip_tags($str);
$str = eregi_replace("\\[img]([^\\[]*)\\[/img\\]","<div class=\"picture\"><img src=\"/imagescripts/phpThumb.php?src=/images/".$picture\\1."&w=200\"></div>",$str);
return nl2br($str);}

$encode = encode($storytext);
echo $encode;


---------------------------------------
The error that I'm getting back and my testing tells me that $picture has the required value and the image path is not being created properly.

Can anyone tell me what I'm doing wrong please?

I assume this syntax is wrong
=/images/".$picture\\1."&

coopster

3:48 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you tried dumping the string to the browser to see what it contains?

function encode($str) { 
$str = strip_tags($str);
$str = eregi_replace("\\[img]([^\\[]*)\\[/img\\]","<div class=\"picture\"><img src=\"/imagescripts/phpThumb.php?src=/images/".$picture\\1."&w=200\"></div>",$str);
exit($str);
return nl2br($str);}