Skip to content
Advertisement

Tag: replace

PHP – replace all “n” Occurrences in a string

I am getting a string in my PHP output with lots of n characters which I would like to convert into <p> to get a new line characters in html outpot. I have tried following: Both of these doesn’t seems to work. Any ideas what’s wrong in the syntax? Answer Try this: PHP: Output:

Jquery removing commas

I’m using the following and it works, but the alerted value opt3 contains commas. How do I remove them? If I select a c & d the alert shows a,c,d but I want it to show acd. Answer What about this? Update: Ok. Like @jreziga mentioned. The return value of .val() will be an array. If you have a string

Replace string in an array with PHP

How can I replace a sub string with some other string for all items of an array in PHP? I don’t want to use a loop to do it. Is there a predefined function in PHP that does exactly that? How can I do that on keys of array? Answer But array_map is just a hidden loop. Why not use

How to replace new lines by regular expressions

How can I set any quantity of new lines with a regular expression? I need to remove every new line (n), not <br/>, between two paragraphs. Answer To begin with, str_replace() (which you referenced in your original question) is used to find a literal string and replace it. preg_replace() is used to find something that matches a regular expression and

Advertisement