Chad Seibert Posted March 18, 2007 Share Posted March 18, 2007 Hello, Community I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script.??? I had this to start with: function ReplaceWithOption($stringtoreplace, $numtabs) { //This creates a string that contains the number of tabs required to tab in and align the code for($x=0; $x < $numtabs; $x++) $tabs .= "\t"; //Replaces all instances of ', ' with </option>\n<option> and aligns it $ret = preg_replace("/, /", "</option>\n".$tabs."<option>", $stringtoreplace); //This adds a blank option at the beginning and adds the starting and ending tags the above code //doesn't do $ret = "<option></option>\n".$tabs."<option>".$ret."</option>"; return $ret; } But is there an easy way to get this to insert the id into it? Thanks for any assistance Chad Seibert Link to comment https://forums.phpfreaks.com/topic/43187-easy-comma-delimited-list-to-dropdown-box-converter/ Share on other sites More sharing options...
chawezul Posted March 18, 2007 Share Posted March 18, 2007 I don't know much about Regex, but I would go about using explode() with the ", " to break it into an array, then loop through it and echo <option id="${exploded[$i]}" /> Link to comment https://forums.phpfreaks.com/topic/43187-easy-comma-delimited-list-to-dropdown-box-converter/#findComment-209700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.