Jump to content

extract specific value from multidim.(?) array


cla

Recommended Posts

Hi, i'm new here, and i need modify some php code but i'm not able to do..

maybe is a stupid question

 

i think this is a multidimensional array

<?php print_r(array_keys($image)); ?>

print: Array ( [0] => post_id [1] => title [2] => content [3] => image [4] => url [5] => url_openblank )

 

<?php echo $image['image'] ?>

 

echo me the images with all attribute

<img width="570" height="570" src="http://wordpressfresh:8888/wp-content/uploads/2014/05/anteprima-03.jpg" class="attachment-full wp-post-image" alt="anteprima-03" />  

 

what I need is only the src value, how can I get it?

 

thanks in advance

claudio

 


 

Link to comment
Share on other sites

Hi Adam,

 

thanks for the replay but this not work for me.. i get an empty echo

 

<?php echo " >> " ,  $image['url'] , " < .. empty"; ?>

 

print :

>>  < .. empty

 

 

But I need the src value inside the image [4] value and not the url [5]

 

I think the image [4] is another array,

 

If I call it

<?php echo $image['image'] ?>

 

I get  the image tag with all attribute

<img width="570" height="570" src="http://wordpressfres...nteprima-03.jpg" class="attachment-full wp-post-image" alt="anteprima-03" />

 

and if I call this

 

<?php echo  $image['image'][0]  ?>

 

or other index number I get the < for 0, i for 1, m for 2 an so on..

 

I think there is a way to get the src value but my php is like my english :)

 

Claudio

Link to comment
Share on other sites

Hi,

 

yes is a multidimensional array..

 

i get this:

 

array(6) {
["post_id"]=>
int(44)
["title"]=>
string(8) "titolo 1"
["content"]=>
string(11) "excerpt uno"
["image"]=>
string(166) "
<img width="570" height="570" src="http://wordpressfresh:8888/wp-content/uploads/2014/05/anteprima-03.jpg" class="attachment-full wp-post-image" alt="anteprima-03" />"
["url"]=>
string(0) ""
["url_openblank"]=>
bool(false)
}

 

 

do you think is possible get the specific value of the src inside the string?

Link to comment
Share on other sites

Hi, just to calrify me, what I mind is:

 

in this case $image is the array taht contain n variable

Array ( [0] => post_id [1] => title [2] => content [3] => image [4] => url [5] => url_openblank

 

and the variable 'image'  inside the array $image is a string composet with all the attribute of the image

["image"]=>
string(166) "
<img width="570" height="570" src="http://wordpressfresh:8888/wp-content/uploads/2014/05/anteprima-03.jpg" class="attachment-full wp-post-image" alt="anteprima-03" />"

 

rigth?

 

best regards

claudio

Link to comment
Share on other sites

 

 

in this case $image is the array taht contain n variable

Yes $image is a variable which holds an associative array, which contains 6 keys called post_id, title, content, image, url and url_openblank

 

 

 

and the variable 'image'  inside the array $image is a string composet with all the attribute of the image

The image key has a string assigned to it. Only you will be able understand that the individual characters used in the string creates the mark-up for an HTML img tag. PHP will not it will just see it as a bunch of random characters.

Link to comment
Share on other sites

For that we have to use the regex expressions .. thanks alot

Yes, for something like that yes. But if you're dealing with more complex HTML you'd pass in the html string to the DOM object (or the simple html helper library) and the use the nesscary methods to get the data you require

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.