0

I have a text editor on my web page, on that text editor i put image and than i use that image in different parts of my website, but in different places the image size differs.

The image in database is stored this way: <div><img width="210" height="150" alt="" src="/portali/userfiles/image/Kategorite/Teknologji/-1.jpg" /></div>

Now in one part of my web site i want to use this same image with different size and for this reason i need some php script to grab only the path of the image, in this sample (/portali/userfiles/image/Kategorite/Teknologji/-1.jpg).

Can some body write here some basic script to do this having in mind that the whole html code of the image is in an single variable.

1
  • i know that the approach is bad, but i use text editor because that was the best and easiest way to upload and use uploaded images from server Commented Feb 12, 2010 at 23:35

2 Answers 2

2

I think your general approach may be wrong depending on what you are doing. Instead of storing the image string in your database just store the file name and possibly a path. Then in your HTML code build the string manually:

<img src='<?= $row['path'] . '/' . $row['image'] ?>' width='XXX' height='XXX'/>

That way you can add as many different parameters as you want.

Also to make it as efficient as possible don't resize your images using style tags or inline width/height, but instead use something like PHP GD or ImageMagick to actually make thumbnails in the sizes you need to display. In the long run this will save you a lot of headaches and bandwidth.

Sign up to request clarification or add additional context in comments.

1 Comment

i know this is the best approach but my situation is like i described on my question, thanks fo your effort
1
$html = '<?xml version="1.0" encoding="UTF-8"?>'.$yourHTMLFromDb;
$elements = new SimpleXmlElement($html);
$url = $elements->img->attributes()->src;

Now im sure i wont be the first to say it but... "Youre doing it wrong". You should only be storing the path to the image in the database (and maybe some other attribnutes) not an html snippet.

4 Comments

i get this error from your code: Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Entity 'euml' not defined in /home6/feksinte/public_html/portali/index.php on line 189
Sorry encoding should be "UTF-8" updated my post.. however the sample html you provided shows only an image within a div where is this entity coming from if this entity is not in the src for the image then you must have other tags in there you didnt include which may change how you reach the element in the dom. the code i posted will only work for the structure you provided in your sample.
again the same error. i have and admin panel where i insert data and for this reason i use an ready made rich text editor (java script based). And when i upload an image using that text editor it stores this image exactly the way i showed you up there. I don't know what i am doing wrong but i still have the same problem
how to print(echo) this in PHP

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.