Digma Posted April 27, 2010 Share Posted April 27, 2010 I am currently working on a new site and will have people adding content to the CMS with limited HTML experience. In order to prevent bad html I thought I would simply have them upload images through the CMS and when they want to use a certain image they simply insert the tag [image2_right] or [image2_left]. Now the number (in this case 2) determines which image to pick up from the database, the left and right apply to the align, the word image is ignored. A typical body content for the item could look like this: [image2_right] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quis nisi ligula, sit amet tincidunt mauris. Quisque vestibulum elit a nisl semper semper. Mauris ultricies pulvinar facilisis. Pellentesque tincidunt viverra dictum. Donec pretium tellus nec leo aliquet eget laoreet tortor fringilla. Sed ac mi tellus. Aenean ut dolor nec enim hendrerit interdum. Duis iaculis nunc vitae leo commodo sodales at non ligula. Integer facilisis fermentum ligula, vestibulum volutpat elit pretium eget. Maecenas ultricies diam a tellus fermentum venenatis. I am using the following code (where longdesc is the body content): $input = $row_item['longdesc']; $pattern = '#\[image([^]]+)_([^[]+)]#i'; $replacement = '<img src="'.$row_item[screenshot.'$1'.].'" align="$2">'; echo preg_replace( $pattern, $replacement, $input ); Now, I think that the regular coders probably have already spotted the problem, but after having tried several different approaches on the $1 bit, I fail to get it working. I was hoping anyone of you could help me properly writing this line so it will be interpreted as $row_item[screenshot1] and thus showing the image. $replacement = '<img src="'.$row_item[screenshot.'$1'.].'" align="$2">'; I simply can't see it for some reason or fix it for that matter. Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/199973-applying-preg_replace-within-rowoutput/ Share on other sites More sharing options...
Digma Posted April 27, 2010 Author Share Posted April 27, 2010 The more I search online, the more I get the feeling this isn't possible, because $1 probably isn't allowed inside $row[...]. Is there another solution? Quote Link to comment https://forums.phpfreaks.com/topic/199973-applying-preg_replace-within-rowoutput/#findComment-1049642 Share on other sites More sharing options...
teamatomic Posted April 28, 2010 Share Posted April 28, 2010 $1 is not allowed anywhere except inside a regex, vars may not begin with a number. Instead of recreating the wheel why not look at something like tinymce. http://tinymce.moxiecode.com/ HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/199973-applying-preg_replace-within-rowoutput/#findComment-1049662 Share on other sites More sharing options...
Digma Posted April 28, 2010 Author Share Posted April 28, 2010 Thanks teamatomic, I'll look into it. The image manager will probably solve the problem Quote Link to comment https://forums.phpfreaks.com/topic/199973-applying-preg_replace-within-rowoutput/#findComment-1049666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.