0

hey i am new to Joomla and always a learner please some one help me that i am exploding the string which i am retrieving from the database of Joomla com_content. it is the path of the image. after fetching the data i have got.

$img="images\/sample-image-big.png"

after that i am exploding it to get only the name of the image so i have removed / after that the result is coming,

 Array (
     [0] => "images
    [1] => sample-image-big.png" )

the problem is that the array[1]=> should be only sample-image-big.png but the " is coming why i want it to remove it , ihave tried all types of explosion but no change , please help me i will be very much thankful to u.

2 Answers2

1

do like this

<?php

$img="images\/sample-image-big.png";

$img=explode("\/",$img);

print_r($img);

output:

Array
(
    [0] => images
    [1] => sample-image-big.png
)
Nambi
  • 11,944
  • 3
  • 37
  • 49
  • What is you program going to do when the image is in the images/animals folder (images/animals/koala.jpg)? I really think explode is probably not how you want to do this. – Elin Jan 17 '14 at 13:32
  • actually i want show image on my template.which the article consisting , so i am trying to use the item.id to fetch the data from the com_content, after that i want to get the image path which creates complications . is there any other way than exploding. – racial cortis Jan 18 '14 at 06:52
0
$img="images\/sample-image-big.png"

stripslash your string

$img=stripslashes($img)// this will give you "images/sample-image-big.png"

now various ways to get what you need. Simplest for me:

$img = str_replace('"images/', '', $img); // will give sample-image-big.png"
$img = str_replace('"', '', $img); // will give sample-image-big.png
andrew
  • 2,058
  • 2
  • 25
  • 33
  • is your $img = str_replace("', '', $img); // will give sample-image-big.png is right because it gives me error. else its right iam close to it . please check and send the correct format. thankyou. – racial cortis Jan 17 '14 at 11:53
  • @racial cortis check now – andrew Jan 17 '14 at 14:06