0

I need to get all the source values from all image inside a container. I'm having some difficulty with this.

Allow me to explain the process. All the data comes from a database. Inside the backofficce the user enter all the text and the image inside a textarea. To separate the text with the image the user must enter a pagebreak. Let's go to the code

while ($rowClients = mysql_fetch_array($rsClients)) {
    $result = $rowClients['content'];
    $resultExplode = explode('<!-- pagebreak -->', $result);
    // with resultExplode[0] I get the code and with resultExplde[1] I get the image

    // Now with I want to get only the src value from resultExplode[1]

I already tried with strip_tags

$imageSrc = strip_tags($resultadoExplode[1]);

but it doesn't print anything.

I found this post but without success. I stopped in the first print_r.

Can anyone help me??

Thanks

Community
  • 1
  • 1
saomi
  • 855
  • 5
  • 16
  • 38
  • What exactly didn't work about the solution proposed in the other question? – codeling Aug 22 '12 at 08:50
  • 4
    Try using PHP [DOM](http://php.net/manual/en/book.dom.php) – Mihai Stancu Aug 22 '12 at 08:50
  • Without a sample of the text I can only assume your text is html like: please confirm this – Waygood Aug 22 '12 at 08:52
  • @nyarlathotep All the process. But for start I couldn't print the array of all images like it does in the first print – saomi Aug 22 '12 at 08:55
  • @user794035: "I couldn't" is a very imprecise statement. What exactly didn't work about it? It probably did execute properly, but just didn't print anything, right? if print_r prints nothing, then your input is probably wrong ;) – codeling Aug 22 '12 at 08:57
  • @Waygood yes its an html tag like this alttext – saomi Aug 22 '12 at 08:57
  • @nyarlathotep yes, the print_r doesn't print nothing. I'm not understanding how can my input is wrong. Can you explain ?? Thanks – saomi Aug 22 '12 at 09:05
  • @user794035: well if the regular expression doesn't find any matches, it probably means that the given string doesn't contain any img tags. – codeling Aug 22 '12 at 09:07
  • @nyarlathotep ok I'll try it again. – saomi Aug 22 '12 at 09:07
  • what would help would be the output of print_r($resultExplode[1]), where you say you "can see the images"; – codeling Aug 22 '12 at 09:08
  • yes with that command I can see the image. That's why a I think the that the input isn't wrong. – saomi Aug 22 '12 at 09:14
  • result of print_r($resultExplode); not just [1] would be more informative – Waygood Aug 22 '12 at 09:33
  • ah ok. What I got was this: Array ( [0] => “1 - Morbi elit nunc, molestie at, ultrices eu, eleifend eu, lorem. Sed pede orci, volutpat sed, congue vel, gravida non, lacus.Vivamus quis metus. Mauris ligula est, auctor vitae, pretium eget, hendrerit [1] => small.png ) Array ( [0] => “ 2- Morbi elit nunc, molestie at, ultrices eu, eleifend eu, lorem. Sed pede orci, volutpat sed, congue vel, gravida non, lacus.Vivamus [1] => benteler.png ) – saomi Aug 22 '12 at 09:44

2 Answers2

0

try foreach, if you can't print it out.. (if that's the problem)

  foreach($resultExplode as $key => $value){
    echo "[".$key."]".$value;
    }
  • if I print_r($resultExplode[1]) I can see the image. That's what your code does. I want to get the source of the image. I said printing the source code, for test, for having a starting point. – saomi Aug 22 '12 at 09:06
0

I found a solution:

continuing with the previous code I worked with the split function.

So I start to strip the tags. This way I get the img isolated from the rest.

$image = strip_tags($resultExplode[1],"<img>");

Because all the img has the same structure like this: <img width="111" height="28" alt="alternative text" src="/path/to/the/file.png" title="title of the image">

I split this string, using " as a delimiter

$imgSplit = split('"', $image);
$src = $imgSplit[3];

Voilá. It's working

What do you say about this procedeure??

saomi
  • 855
  • 5
  • 16
  • 38