PHP – Protection of special characters of regular expressions

Code sur écran d'ordinateur

If you want to use a regular expression to, for example, search for a word in a paragraph, it is important to protect your variable. To do this, just use the following function: preg_quote thong ($str thon[, string $delimiter = NULL ]g) For example: foreach ($aReque[‘keywords’]st as $sKeyword) $sKeyword – preg_quote ($sKeyword); $pattern ' ' … Read more

Javascript – Iframe – the address where the iframe is located

MacBook avec code sur un bureau

For security reasons, you can’t directly reach the page outside the iframe from inside it. However, we can retrieve information from the browser. To retrieve the parent’s address, i.e. the URL of the page where the iframe is added, just write this: <script type=”text/javascript”> var url (window.location!) – window.parent.location)? document.referrer: document.location; alert (url); </script> This … Read more

PHP – mb_strlen to regain the size of a character chain and not strlen

MacBook avec code sur un bureau

By default I’ve seen a lot of code using strlen to retrieve a character string size. Unfortunately this method returns the number of bytes used rather than the number of characters. That is, depending on your encoding, you’re going to have differences of +/- 1 character. To avoid this, you could do: strlen (utf8_encode($string)) But … Read more

PHP – Replace accents with their counterparts.

MacBook avec code sur un bureau

A small function to replace accented characters with their unaccented equivalent. function normalize_str ($str) { $invalid ' array,'' 'S', '''s', ''Dj', '''Dj', ''Z', ''Z', ''Z', ''Z', ''Z', ''Z', ''Z', ''Z', ''Z', ''Z', 'Z', 'C', ''C', ''C', ''C', ''C', ''A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'EA', ''A', ''A', ''A', ''C', ''E', 'E', 'E', 'E', … Read more