Jump to content

Text substitution - help needed


lxndr

Recommended Posts

I'm trying to write a function that will read in a text document containing various bespoke tags which I then expand into the appropriate HTML.  I've done most of them but was wondering if someone could help me with this particular one .. I'm guessing I should be using preg_replace but can't seem to get it to work.

 

I have a variable called $rec_id which is an integer. The following is the conversion I want to perform:

 

in text file:      <image 1/jpg>

should be converted to :  <img src = "story_images/1347-1.jpg" style="float:left;padding:5px;">

 

where the conversion string is all fixed as above apart from the bit in colour and in the above example $rec_id was 1347.  Here are another couple of examples to illustrate the above:

 

$rec_id:  1281

tag in text file:  <image 2/gif>

tag replaced with:  <img src = "story_images/1281-2.gif" style="float:left;padding:5px;">

 

 

$rec_id:  763

tag in text file:  <image 4/jpg>

tag replaced with:  <img src = "story_images/763-4.jpg" style="float:left;padding:5px;">

 

 

Any help much appreciated.

 

.

 

 

 

 

Link to comment
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.