find a "imagefilename.jpg"  in a text with php

Posted on 2011-02-26
Last Modified: 2012-05-11
How to find a image filename in a text with php to make an embeded image  ?....

Well, I do have an exported text (a diary) in plain text ... in this text there are filenames of the images attached to the specific day .. how can I replace the filename with a new <img src="thefile.jpg"> with php?
And how can I make a CSS to style it? ... first line = h2 etc ...


Monday 23rd of May
This is the day. The sun is bright and live is good

Photos: IMG00283750.jpg, IMG985749.jpg

Question by:Hans Inge Hagen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34988855
What is the entry pattern ? I mean is it always:
Photos: a.jpg, b.jpg

Open in new window

Could the images appear in two or more lines ? Can they be separated with empty line ?

Author Comment

by:Hans Inge Hagen
ID: 34988882
No. We need to search for the xxxx.jpg filename in all the text ... when found we need to add the tags to embed the image .. Example:  IMG_0001.jpg  converted to  <img src="IMG_0001.jpg">

Expert Comment

ID: 34988915
preg_replace('/ ([^ ]+\.jpg)/i','<img src="$0" />',$text);

Open in new window


Accepted Solution

LAMASE earned 50 total points
ID: 34988921
sorry, use $1 instead of $0

Author Closing Comment

by:Hans Inge Hagen
ID: 34988953
Very good! Thanks a milliion

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
responsive menu pushes content down instead of going over top 3 30
Joomla Editing 3 24
php non-object 7 29
My tooltip is not displaying correct 11 20
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question