Portal Home > Knowledgebase > Articles Database > substr an array
substr an array
Posted by -Edward-, 09-26-2007, 11:54 AM |
Hi Folks,
I'm having a little trouble breaking down this array:
This is inside a function called GetMy.
I've created another function that I want to grab the final 3 letters of what the array displays.
So, if it ends in .gif it displays:
and if it ends in .swf it displays:
Here's my function:
It shows the following though:
Whether it's an img or an swf file, Can anyone help?
|
Posted by foobic, 09-26-2007, 12:23 PM |
1. We'd need to see the whole of function GetMy - at a guess it's echoing a result instead of returning it as you want.
2. Be real careful about the difference between:
and
The first is an assignment - it's always true, no matter what value $display had before.
|
Posted by -Edward-, 09-26-2007, 12:33 PM |
Sorry,
It is actually:
Here's my GetMy() function:
|
Posted by isurus, 09-26-2007, 01:27 PM |
As foobic said: your GetMy() function is echoing a result instead of returning it.
Try this:
(I'm assuming that $pimages and $product_code are defined elsewhere)
You are also grabbing the first 3 characters of the string, not the last 3:
If you want to grab the last three characters you should use this:
It may also be worth you checking for it being an unknown file type:
eg
HTH,
Simon
|
Posted by -Edward-, 09-26-2007, 02:38 PM |
That appears to of done the trick! changing display to:
$display = substr($get, -3);
Thank you.
|
Add to Favourites Print this Article
Also Read