Jump to content


Photo

help with str_replace


  • Please log in to reply
2 replies to this topic

#1 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 16 April 2006 - 05:36 PM

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!
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]

#2 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 16 April 2006 - 06:21 PM

ahhh

Sorry guys, my fault i was replacing the wrong thing..nevermind.. this can be closed.
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 April 2006 - 06:26 PM

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

Ken





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users