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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.