Hi All,

I have a content management system that I'm building and I'm having issues 
matching a variable that needs to be replaced with rows from a database. 
Basicly I have something setup similar to bbcode, where a user enters 
html-like text for formatting - eg: [b]bold text[/b]. I'm now adding the 
ability to link photos in this formatted text. 

In order to display the page using html, I obviously need to convert the 
special tags to their real ones. With the images, I'm actually pulling 
data [image name, width, height, image_placer, alignment, etc] from a 
database. There can be more than 1 image on a page [and more than 10, 
actually]. The user would simply type into the CMS editor something like, 
"Here is a photo of my dog ###Image1###" The ###Image1### is a 
placeholder. The user gets assigned a placeholder for each image they 
upload. They then assign different parameters to that image [a caption, 
and center/left/right alignment].

In order to display this data, I call a function called vencode() on the 
page that a user will see:

<?php
$message = vencode("$message");
echo "$message"; ?>

The entire page's content section is inside $message. The vencode() 
function looks like this:

function vjencode($message) {
 
 $message = " " . $message ;

##--- [b] and [/b] for bolding text.
 $message = preg_replace("/\[b\](.*?)\[\/b\]/si", "<b>\\1</b>", $message);

##--- [i] and [/i] for italicizing text.
 $message = preg_replace("/\[i\](.*?)\[\/i\]/si", "<i>\\1</i>", $message);

    
##--- Patterns and replacements for URL and email tags..   
        $patterns = array();
        $replacements = array();

##--- [url]xxxx://www.seweb.uci.edu[/url] code..
        $patterns[0] = "#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si";
        $replacements[0] = '<a href="\1\2">\1\2</a>';
        
        
##--- [url]www.seweb.uci.edu[/url] code.. (no xxxx:// prefix).
        $patterns[1] = "#\[url\](.*?)\[/url\]#si";
        $replacements[1] = '<a href="http://\1";>\1</a>';

##--- [url=xxxx://www.seweb.uci.edu]Social Ecology Home[/url] code..
        $patterns[2] = "#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si";
        $replacements[2] = '<a href="\1\2">\3</a>';

##--- display photos [having problems with this]
$patterns[3] = "#\#\#\#Image(.*?)\#\#\##si"; 
// this matches just fine strings like ###Image1### and ###Image2###


 if ($_GET[ppdid] != "") { // the ppdid var is passed in the URL 
 $sel_image = "SELECT * from ppd_photos where ppd_id = '$_GET[ppdid]' AND place_holder 
= '$thephoto[0]'";
// in this case, the page with a ppdid of '3' has 2 images, who's 
// placeholders are: ###Image1### and ###Image2###
 $sel_image_result = safe_query($sel_image);
 $sel_image_row = mysql_fetch_array($sel_image_result);
 $image_id = $sel_image_row["image_id"];
 $image_name = $sel_image_row["image_name"];
 $caption = $sel_image_row["caption"];
 $width = $sel_image_row["width"];
 $height = $sel_image_row["height"];
 $image_alignment = $sel_image_row["image_alignment"];
// replacements[3] is all one one line -sorry about word wrap!
 $replacements[3] = "<br><table border=0 cellspacing=2 cellpadding=0 
width=\"$width\" align=\"$image_alignment\"><tr><td><img 
src=\"/uimages/$image_name\" 
height=\"$height\" width=\"$width\" border=1></td></tr><tr><td><font 
class=\"caption\">$caption<font></td></tr></table><br>";
}

$message = preg_replace($patterns, $replacements, $message);

return $message;
} //end of function

In the case of the page with the ppdid of '3', there are two images 
assigned to that page. However, when running the above code, I two photos 
of the first listed image! Eg, the text in $message looks like this:

---------------------
Hello world, look at my [b]cat[/b]: ###Image1### Nice, huh?
And now look at my [b]dog[/b]: ###Image2### Not so nice, eh?
---------------------

The substitution code also translates linebreaks as <br>s and such, but I 
didn't think I needed to include the entire list of substitutions it 
makes. 

I'm sure I need a while loop in there somewhere, but I can not figure out 
where. I know the code is  looping through the other substitutions ok, 
since all text that should be bold is, and all links that need to be made 
into valid URIs are. 

The db query does run fine if running within mysql, and substituting 
###Image1### and ###Image2### for $thephoto[0]. I know that $thephoto[1] 
simply contains a "1" [since that is the value of $patterns[3]].

Any tips about where I need to loop and how, would be most appreciated! 

/vjl/

-- 
Vince LaMonica               UC Irvine,  School  of  Social Ecology
 W3 Developer       <*>      116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]                  http://www.seweb.uci.edu/techsupport

 If it be now, 'tis not to come; if it be not to come, it will be now;
 if it be not now, yet it will come: the readiness is all." 
                   -- William Shakespeare, "Hamlet." 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to