cla Posted May 7, 2014 Share Posted May 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
adam_bray Posted May 7, 2014 Share Posted May 7, 2014 Looks like a normal array with keys. Try this - echo $image['url']; Quote Link to comment Share on other sites More sharing options...
cla Posted May 7, 2014 Author Share Posted May 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 7, 2014 Share Posted May 7, 2014 Hi, we can speculate all day long about what the array might contain. But it would be much easier if you simply inspected it: var_dump($image); What does that say? Quote Link to comment Share on other sites More sharing options...
cla Posted May 7, 2014 Author Share Posted May 7, 2014 Hi, yes is a multidimensional array.. i get this: array(6) {["post_id"]=>int(44)["title"]=>string( "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? Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted May 7, 2014 Solution Share Posted May 7, 2014 Use regex on $image['image'] to get the value of the src attribute preg_match('~src="([^"]+)"~', $image['image'], $m); $image_src = $m[1]; Quote Link to comment Share on other sites More sharing options...
trq Posted May 7, 2014 Share Posted May 7, 2014 yes is a multidimensional array.. Nope, it is not. Quote Link to comment Share on other sites More sharing options...
cla Posted May 7, 2014 Author Share Posted May 7, 2014 Hi, yes image is a string so is a normal array.. and the regex expression is the rigth way thank yuo all !! Claudio Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 7, 2014 Share Posted May 7, 2014 yes image is a string so is a normal array.. No, an array is an array. A string is a string. Just that PHP allows you to treat a sting like an array. This is due to PHP loosely coupled nature. Quote Link to comment Share on other sites More sharing options...
cla Posted May 8, 2014 Author Share Posted May 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 8, 2014 Share Posted May 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
cla Posted May 8, 2014 Author Share Posted May 8, 2014 PHP will not it will just see it as a bunch of random characters. For that we have to use the regex expressions .. thanks alot Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 8, 2014 Share Posted May 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.