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 code for generating decent-looking coupon codes (mix of letters and numbers)
For an ecommerce site I want to generate a random coupon code that looks better than a randomly generated value. It should be a readable coupon code, all in uppercase with no special characters, only …
How can I find where I will be redirected using cURL?
I’m trying to make curl follow a redirect but I can’t quite get it to work right. I have a string that I want to send as a GET param to a server and get the resulting URL. Example: String = Kobold …
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
How to generate unguessable “tiny url” based on an id?
I’m interested in creating tiny url like links. My idea was to simply store an incrementing identifier for every long url posted and then convert this id to it’s base 36 variant, like the following in PHP: The problem here is that the result is guessable, while it has to be hard to guess what the …
How to download file as document in Internet Explorer? [closed]
My file download as document is not working in IE. How can I write code in PHP to download the file correctly in Internet Explorer
Add spaces between words in a camelCased string then uppercase the first word
I have two types of strings, hello and helloThere. What I want is to change them so they read like: Hello and Hello There depending on the case. What would be a good way of doing this? Answer you can use ucwords like everyone said… to add the space in helloThere you can do $with_space = preg_replace(…