Short Tag – Web Development Blog

Entries for February, 2012

Javascript function to trim any character

Today I want to share a javascript function that will trim any character from the beginning and the end of the string.
The function will trim all occurrences of the character from the beginning and the end of the string.

function trim_chars(str, char)

while (str.substr(0, 1) == char)
str = str.substr(1);

var nrt = str.length;
while (str.substr(nrt-1, 1) == char)
str = [...]

PHP str_replace

PHP’s str_replace function will replace every occurrence of the selected string with another string.

echo str_replace("car", "bike", "That car is red!");

The code above displays the text: That bike is red!
Function parameters:
str_replace(searched_string, replacement_string, target_string, count)
searched_string – the string that will be replaced
replacement_string – the string that will be used to replace the searched string
target_string – the string [...]

jQuery animate() is not working on element’s children in IE8

Today I encountered a problem I thought I should post about.
When you try to animate an element that has children (for example DIVs) positioned relative or absolute on Internet Explorer 8 these children will not animate, in fact they will not do anything the parent does. I tested this animating the opacity.

<div class="main">
<div class="first"></div>
<div class="second"></div>
<div [...]