replace space with "-" in field from database

replcae space with "-" when pulling data from database

Page 1 of 1

1 Replies - 924 Views - Last Post: 03 December 2009 - 06:15 PM Rate Topic: -----

#1 skywaves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-June 09

replace space with "-" in field from database

Posted 03 December 2009 - 05:36 PM

Hi i am creating a form for poll.

i have two tables in database.one is for questions and other for database.

i am pulling answer field from database and setting that as label for input. it is working fine but i am getting error from html validator about no space and "&" sign.

how i can replace space with some character like "-".

please help


HTML
<label for="Pride & Prejudice_4">Pride & Prejudice</label>
			<input type="radio" name="vote" id="Pride & Prejudice_4" value="4" /><br/>


PHP

 <label for="<?php echo $vote_answer . '_' . $vote_id; ?>"><?php echo $vote_answer?></label>
			<input type="radio" name="vote" id="<?php echo $vote_answer . '_' . $vote_id; ?>" value="<?php echo $vote_id?>" /><br/>



Is This A Good Question/Topic? 0
  • +

Replies To: replace space with "-" in field from database

#2 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 330
  • Joined: 11-July 07

Re: replace space with "-" in field from database

Posted 03 December 2009 - 06:15 PM

View Postskywaves, on 3 Dec, 2009 - 04:36 PM, said:

Hi i am creating a form for poll.

i have two tables in database.one is for questions and other for database.

i am pulling answer field from database and setting that as label for input. it is working fine but i am getting error from html validator about no space and "&" sign.

how i can replace space with some character like "-".

please help


HTML
<label for="Pride & Prejudice_4">Pride & Prejudice</label>
			<input type="radio" name="vote" id="Pride & Prejudice_4" value="4" /><br/>


PHP

 <label for="<?php echo $vote_answer . '_' . $vote_id; ?>"><?php echo $vote_answer?></label>
			<input type="radio" name="vote" id="<?php echo $vote_answer . '_' . $vote_id; ?>" value="<?php echo $vote_id?>" /><br/>



A simple replace method would be:
$string = "I like this code.";
$string = str_replace(" ", "-", $string);
print $string;



Would output:
I-like-this-code.

Hope this helps

-huzi

This post has been edited by huzi8t9: 03 December 2009 - 06:16 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1