Jump to content

help with str_replace


TEENFRONT

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!
Link to comment
https://forums.phpfreaks.com/topic/7551-help-with-str_replace/
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
Link to comment
https://forums.phpfreaks.com/topic/7551-help-with-str_replace/#findComment-27515
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.