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

jQuery – Word and Character Counter

MacBook avec code sur un bureau

A small script to count the number of words and/or characters in an input or textarea field <input id="text" name="text" type="text"> <span id="count"></span>"; We place the script in jQuery’s ready function to make sure the HTML has been fully loaded. <script></script> (document).ready (function) count ($("#text"),$("#count") $("#text"). count ($("#text"),$("#count") }); }); function count (src,dest) var txtVal … 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