homepage Welcome to WebmasterWorld Guest from 54.211.113.223
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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

10+ Year Member



 
Msg#: 6175 posted 7:26 pm on Dec 18, 2004 (gmt 0)

I keep getting

parse error, unexpected T_CONSTANT_ENCAPSED_STRING

 

jatar_k

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



 
Msg#: 6175 posted 8:59 pm on Dec 18, 2004 (gmt 0)

what is the str_replace statement, that will help us explain the problem

ocelot

10+ Year Member



 
Msg#: 6175 posted 9:07 pm on Dec 18, 2004 (gmt 0)

I'm sorry, the code is

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

Finger

10+ Year Member



 
Msg#: 6175 posted 9:28 pm on Dec 18, 2004 (gmt 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 $.

jatar_k

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



 
Msg#: 6175 posted 9:31 pm on Dec 18, 2004 (gmt 0)

try

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

the single quotes will stop the $ from being resolved.

Finger

10+ Year Member



 
Msg#: 6175 posted 9:41 pm on Dec 18, 2004 (gmt 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);

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved