Jump to content


Photo

PHP Newbie needs HELP


  • Please log in to reply
3 replies to this topic

#1 rishum

rishum
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 September 2006 - 04:56 AM

Hello everyone,

I have only recently started dabbling with PHP.
I don't have a strong programming background but am determined to learn PHP to enhance my professional profile. I have joined this forum to seek help from people who are much more adept at all things PHP!  :)

What I am currently trying to do is to catch a string, remove the white spaces preceeding and trailing the string, and then replacing the spaces between the words that might be in a string with the # symbol.

My problem is that using the trim() function, all the white spaces may be removed but I will not be able to replace the spaces between the words with a #. I am not able to understand how to go about this. Should I be using a loop to check all characters one-by-one and wherever a space is encountered amongst the characters, it be replaced by a #? Or is there any other simpler way to do it?

Also, can anyone kindly direct me to any code example to achieve what I want to?

I eagerly look forward to hearing form you guys.

Thanks and regards,

Rishum




#2 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 11 September 2006 - 05:15 AM

You'd want to use str_replace()
http://www.php.net/m...str-replace.php

#3 kenrbnsn

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

Posted 11 September 2006 - 05:22 AM

The trim() function only removes white space from the beginning and end of a string, never from inside the string. To do that use the str_replace() function as Wintergreen mentioned.

Ken

#4 rishum

rishum
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 September 2006 - 05:42 AM

Hey guys,

Thanks a ton for your guidance!
I will check out this function right now  :)

Rishum




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users