In my PHP forum i want people to insert pictures just by inserting the number/ID of the picture (which they can see in an online photoalbum)
I am looking for a function that can read a string from their posts for example
“bla bla and look at this amazing picture [IMG]234[/IMG] isn’t it awesome …”
then finds the picture in a database with the ID 234 and replaces [IMG]234[/IMG] with
<img src = "path/to/image.jpg" />
preg_replace wouldn’t work 🙁 does anyone have an Idea?
thanks for Your help in advance
Your code needs to make a db call to get the path from the ID.
Use a tag parser or basic regex to match
\[img][0-9]+\[/img]. (preg_match)Then query your database for the path with the match result as the ID.
Finally, use
str_replaceto replace the original “[img]$match[/img]” withExample (pseudo, look these functions up first)
Note: this will only work with tags in lowercasse: img and not with IMG, iMG, ImG and so on.