How To Take Out Image Name And Format Or Extension From URL OR IMG Tag

59 views

Use preg_match OR preg_match_all to solve this problem.Here i have given simple Example for taking name and image format or extension and stored it in array:

Example1: Taking name and image format or extension from

  1. <img src>


Here is the code:

  1. $url=‘<img src="http://www.computereducationworld.com/logo.jpg">’;
  2. preg_match_all(‘/ (src)(\=\’|\=\”)http:\/\/([a-zA-Z0-9\-\_\/\.]+|)\/([a-zA-Z0-9\-\_]+)\.([a-zA-Z]+)(\’|\”)/’,$url,$ImagesArray1,PREG_SET_ORDER);
  3. print_r($ImagesArray1);

Output:

  1. [0] => Array (
  2. [0] => src="http://www.computereducationworld.com/logo.jpg"
  3. [1] => src
  4. [2] => ="
  5. [3] => www.computereducationworld.com
  6. [4] => logo
  7. [5] => jpg
  8. [6] => " ) )
  9.  

Copy the code from here: Open Close

Example 2: Taking name and image format or extension from url:

  1. $url="http://www.computereducationworld.com/logo.jpg";
  2. preg_match_all(‘/http:\/\/([a-zA-Z0-9\-\_\/\.]+|)\/([a-zA-Z0-9\-\_]+)\.([a-zA-Z]+)/’,$url,$ImagesArray1,PREG_SET_ORDER);
  3. print_r($ImagesArray1);

Output:

  1. [0] => Array (
  2. [0] => http://www.computereducationworld.com/logo.jpg
  3. [1] => www.computereducationworld.com
  4. [2] => logo
  5. [3] => jpg
  6. ) )

Copy the code from here:Open Close



« Google Set To Change Ranking Algorith Count Character Written in textarea or textbox in javascript »
Posted on Wednesday, April 22nd, 2009 at 1:34 pm under PHP Script, PHP Tricks | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?