Skip to content

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 …

PHP error_log errors to MySQL

In a previous ticket i asked about logging PHP errors in MySQL which gives me: I can make this work but only if it is triggerred like this: However, I also want the error handler to be called for all errors such as syntax errors like: But these errors are just outputted to the screen, what am i doing wrong?

PHP Append to empty string without error

I have got the following issue, my function appends code to a string $string ($string .= bla), but in the beginning the string is empty, so I get this error message A PHP Error was encountered Severity: Notice Message: Undefined variable: $string Filename: libraries/file.php Line Number: 90 Of course if I def…

Print the keys of an array

I could not figure out how to pass a variable number of variables into a function. I thought passing in an array and using the array keys for the variables names could replace the need to pass extra variables into the function, and it worked (I’m sure there is a better way to accomplish this, suggestion…

Check and return duplicates array php

I would like to check if my array has any duplicates and return the duplicated values in an array. I want this to be as efficient as possible. Example: Also the initial array is always 5 positions long Answer this will be ~100 times faster than array_diff