Need code to remove '#'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
QuickSnail
Forum Commoner
Posts: 46
Joined: Fri Dec 21, 2007 11:13 am

Need code to remove '#'

Post by QuickSnail »

Is there a way to remove a #.

I'm making a php generator for myspace layouts. But the problem is.. My color wheel produces the #html color.
Well myspace funks up when you give a color like #FF0000, what i need is to just have FF0000. ( Not necessary that color. )


Is there a tag or code of some sort that i could have on the second page or first don't matter to remove the '#' apon hitting the submit.
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

Code: Select all

str_replace("#", "", "#ffffff");
QuickSnail
Forum Commoner
Posts: 46
Joined: Fri Dec 21, 2007 11:13 am

Post by QuickSnail »

Now will that only take the # out of ffffff or will it take it out for all colors.

EDIT:

And where do i pu it exactly. Anywhere? Sorry iI'm rather new..
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

I presume you would pass the value via posting it, in which case if the form field where the value is stored is called "color" for example, you could use this:

Code: Select all

$_POST['color'] = str_replace("#", "", $_POST['color']);
EDIT:

In your HTML, you then have this:

Code: Select all

<input type="text" name="color" value="<?= $_POST['color']; ?>" />
QuickSnail
Forum Commoner
Posts: 46
Joined: Fri Dec 21, 2007 11:13 am

Post by QuickSnail »

ahhh k. Lemme try it out. Thanks.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

To make it easy you could apply the replace to the entire $_POST array.

Code: Select all

<?php
$_POST = str_replace('#', '', $_POST);
?>
Post Reply