Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/199973-applying-preg_replace-within-rowoutput/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.