Welcome to WebmasterWorld Guest from 54.167.40.25

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

str_replace: how do I replace spaces and $ dollar signs?

     
7:26 pm on Dec 18, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 22, 2004
posts:59
votes: 0


I keep getting

parse error, unexpected T_CONSTANT_ENCAPSED_STRING

8:59 pm on Dec 18, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


what is the str_replace statement, that will help us explain the problem
9:07 pm on Dec 18, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 22, 2004
posts:59
votes: 0


I'm sorry, the code is

$item = "DVD player: $53.92";
$item2 = str_replace(" ", "", $item);
$item3 = str_replace("$", "", $item2);

9:28 pm on Dec 18, 2004 (gmt 0)

New User

10+ Year Member

joined:Sept 19, 2003
posts:22
votes: 0


The T_CONSTANT_ENCAPSED_STRING error usually means that you forgot a ; after some line in your code. Your use of str_replace is correct if your goal is to remove the spaces and $.
9:31 pm on Dec 18, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


try

$item = "DVD player: $53.92";
$item2 = str_replace(' ', "", $item);
$item3 = str_replace('$', "", $item2);

the single quotes will stop the $ from being resolved.

9:41 pm on Dec 18, 2004 (gmt 0)

New User

10+ Year Member

joined:Sept 19, 2003
posts:22
votes: 0


Sorry, in my last post I didn't catch the $ in the double quotes (I ran the code and it worked for me). jatar is correct, and you can also use double quotes if you escape the $ with \. So the last line would be:

$item3 = str_replace("\$", "", $item2);