Winona asked:
I made a PHP form and part of it needs to be in list format. I don’t know how to write a function that replaces “-” and “*” with bullet points.
I made a PHP form and part of it needs to be in list format. I don’t know how to write a function that replaces “-” and “*” with bullet points.
Please help!


5 Comments to 'How do I write a PHP code that replaces asterisks and dashes with bullet points?'
March 27, 2010
There’s already a function to do that - str_replace()
March 29, 2010
are you using HTML along with php? easy chuck those inside a list tag
April 1, 2010
It would be really simple to do this with an unordered list in HTML. However, if you are set on using PHP:
PHP makes it a bit more complicated than it needs to be though…if you could just use the list element in HTML.
> Note that you should use the ASCII HTML code for the bullet point…
April 4, 2010
Your best resource is going to be to lookup functions and see examples of code.
The easiest way to solve your problem is with the “str_replace” function which is documented here:
In using this function you can replace one element at a time as so:
To replace both characters in one line of code, you can pass an array of elements that you wish to replace to the str_replace function as so:
The above function works with simple replace scenarios. A much more powerful and complex function is “preg_replace”. This function can replace characters matching a pattern. Below is an example:
Hope this helps!
April 5, 2010
Well, Bulletpoints are come in html tab. So you have to check your data and try to bring it in a way so that you can easily make li tags in it.
If you still want to replace then use regular expression. Something like below
In the above code, $strResult will contains $strTest but * and - is replaced with two underscores __
Leave a comment