-1

I'm new to PHP and I've been searching all day how to do this, but how would I make it so that when a user inputs info into a database

It pulls the data as "blah-bah"

Instead of "Blah Blah"

WittyPleb
  • 553
  • 2
  • 10
  • 22
  • What is your input? Can you show us that code sample? – Prasad Rajapaksha Feb 14 '12 at 01:16
  • Well the way I have it is someone puts in a name say for example "My Name" I want to be able to pull the data as "my-name" but and still be able to view it dynamically without adding a new field in my database (if that makes sense lol) – WittyPleb Feb 14 '12 at 01:19
  • There is an answer given. What do you think about that. Is that what you want or something else. I didn't understand this part of your comment "but and still be able to view it dynamically without adding a new field in my database" . – Prasad Rajapaksha Feb 14 '12 at 01:25
  • 1
    Sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Care to clarify what you *actually* want to do? – deceze Feb 14 '12 at 01:30
  • Never mind, I found out what I had to do. I selected the information where the name equals the variable I put in but with `strtolower(str_replace('-', ' ', $name))` As the WHERE part That makes it so that it selects "My Name" when "my-name" was inputted in the URL Then that was basically it. Thanks for all your help though! – WittyPleb Feb 14 '12 at 01:32

1 Answers1

6
echo strtolower(str_replace(' ', '-', 'Blah Blah'));
deceze
  • 510,633
  • 85
  • 743
  • 889
  • 1
    regular expression, $string = preg_replace('/\s+/', '-', $string); if you want to remove more than 1 –  Feb 14 '12 at 01:17
  • 3
    `str_replace()` will remove more than one. The benefit of a regular expression is if you wanted to remove additional whitespace (e.g. a tab) – Jason McCreary Feb 14 '12 at 01:20
  • It depends whether you want to replace all spaces with a dash, or *collapse* continuous whitespace into *one* dash. Your can do the latter with regexen. – deceze Feb 14 '12 at 01:22