Kailash Yadav

Just another script samurai !!

Archive for the 'Javascript' Category

Regular expression for HTML tags in string

Here is one of most powerful and used regular expression which was used by every developer once in their life for sure.

How to select content or string inside a HTML tag using regular expression in all languages.

I am sharing this regular expression with you. This regular expression is useful when you fetching content from Other Website using cURL.
]*>(.*?)} ?>

Here is one small example:
//Example to get text inside given tag
$content = file_get_contents("http://www.example.com");
$tag= 'h1'; //we will extract page heading

preg_match("{<'.$tag.'[^>]*>(.*?)}", $content, $match);
$data = $match[0];
echo $data;
?>

Note: This only returns text(string or HTML) inside the Tag you have given. It doesn’t include that tag.

posted by Kailash Yadav in Javascript,PHP and have No Comments

Defer Banner Ads or JavaScript To Load After Page Loads

There are many times when you might want a certain banner ad to load only after you page loads fully, however, not everyone is an expert in AJAX or JavaScript for that matter to make change code and make the code efficient.

If you are a webmaster and have been worried about slow page load times, there is a easier way to defer certain banners or JavaScript code to load after the browser has rendered the rest of the page. This trick can be used for both inline and external JavaScript by using the “defer” attribute specified in HTML 4.01 and later.

To defer banner ads or any JavaScript code to load after the entire page has rendered, just add the attribute defer=”defer” to the script tag and the browser will ignore the code within the script and load it after it has finished loading the rest of the content.

Here are some examples of using the defer attribute with a script:

//inline JS example
//external JS example


Using this trick will ensure that your non JavaScript content loads quickly enough so that it does not hinder a user’s browsing experience. However, it may not improve the overall page load times since the browser will continue to load the deferred JavaScript content after the rest of the page has loaded.

posted by Kailash Yadav in Javascript,Open Source and have Comments (3)