Jump to content

Archived

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

TEENFRONT

help with str_replace

Recommended Posts

hey , im working on a smiley site and i do this..

upload smiley big-smile001.gif

then in the php file i set the row as the image name so

$smileyname=$r["smileyname"];// $smileyname will = big-smile001.gif

$getrid = array(".gif");
$cleaned = str_replace($getrid, "", "$smileyname");

i get rid of the .gif bit so i can display just the name of the smiley without the .gif but it looks like the str_replace is getting rid of my 0's

coz it will output big-smile1 ( instead of big-smile001 ) , and this is a problem coz i link to the file using the outputted result... and big-smile1 isnt a file..big-smile001 is.

so, any str_replace solutions for not getting rid of my 0's? Much appreciated if anyone knows the answer! TA!

Share this post


Link to post
Share on other sites
ahhh

Sorry guys, my fault i was replacing the wrong thing..nevermind.. this can be closed.

Share this post


Link to post
Share on other sites
Don't make $getrid an array, just do:
[code]<?php
$getrid = '.gif';
$cleaned = str_replace($getrid, '', $smileyname);
?>[/code]
Here's a more generic version, so you don't have to change you code if you decide to use both .gif * .jpg files:
[code]<?php
$x = pathinfo($smileyname);
$cleaned = str_replace('.' . $x['extension'],'',$smileyname);
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

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.