merylvingien Posted February 20, 2010 Share Posted February 20, 2010 Hi Guys, i am playing with a bit of code and i have run up against something i can figure out. I have a sort of blog, but till now i havent allowed images or any html input. I have been playing with bb code to spice things up. I have the bbcode bit sorted out for the moment. What i am trying to do is: if someone posts an image, i need to detect that an image has been posted, then resize for the limits of the page layout. I have got to here so far: $text is the blog text posted by user (coming to page from database) $text= nl2br($text); $simple_search = array( //added line break '/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', //added textarea for code presentation '/\[codearea\](.*?)\[\/codearea\]/is', //added pre class for code presentation '/\[code\](.*?)\[\/code\]/is', //added paragraph '/\[p\](.*?)\[\/p\]/is', ); $simple_replace = array( //added line break '<br />', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', // added nofollow to prevent spam '<a href="$1" rel="nofollow" title="$2 - $1">$2</a>', '<a href="$1" rel="nofollow" title="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //added alt attribute for validation '<img src="$1" alt="" />', '<a href="mailto:$1">$2</a>', '<a href="mailto:$1">$1</a>', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //added textarea for code presentation '<textarea class="code_container" rows="30" cols="70">$1</textarea>', //added pre class for code presentation '<pre class="code">$1</pre>', //added paragraph '<p>$1</p>', ); // Do simple BBCode's $text = preg_replace ($simple_search, $simple_replace, $text); then display text! I have a limit of 480 pixels width to play with. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/192744-bbcode-image-resize-problem/ Share on other sites More sharing options...
alpine Posted February 20, 2010 Share Posted February 20, 2010 What you are doing is allowing an img src from another location, not uploading THE image to YOUR server - so the easiest way for you is probably to solve it in CSS by adding an image class and setting max-width #bbcode img { max-width: 480px; } Link to comment https://forums.phpfreaks.com/topic/192744-bbcode-image-resize-problem/#findComment-1015333 Share on other sites More sharing options...
merylvingien Posted February 20, 2010 Author Share Posted February 20, 2010 Thanks alpine, i didnt even think of doing it that way Works a treat Link to comment https://forums.phpfreaks.com/topic/192744-bbcode-image-resize-problem/#findComment-1015336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.