SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy decrese this function time

    Hi every body ..
    I have a problem which make "Internal Server Error" error appear in the page and I don't know what is it.. when I remove str_replace it work fine.

    note: I use simplehtmldom to extract the script code from the page ..


    can some one please help me to optimize this code

    Code:
    function replace_gcode($code){
    	$html =  str_get_html($code);
    	$ori  =  str_get_html($code);
    
    	$var_12_100x100 = 'template area';
    	$var_12_100x200 = 'template area';
    	$var_12_100x300 = 'template area';        
    
    	$j = 0 ;
    	$rep = true;
    	foreach($html->find('script') as $e) {
    		$val = $e->outertext;
    		$src = $e->src;
    
    		if ( ($src == '{str1}' || strpos($src,'{str2}')) && $rep) {
    			$ori = str_replace($val , '' ,$ori);
    			$rep = false;
    		}
    		
    		if(strpos($val,'string_area')){
    	
    			$tmp = explode(chr(10),$val);
    			for($i=0;$i<sizeof($tmp);$i++){
    				if(strpos($tmp[$i],'width')){
    					$adsWidth = str_replace(array('wwidth = ',';'),'', trim($tmp[$i]) );
    				}
    	
    				if(strpos($tmp[$i],'height')){
    					$adsHeight = str_replace(array('hheight = ',';'),'', trim($tmp[$i]) );
    				}
    			}
    			$make_ads_var = 'var_12_'.$adsWidth.'x'.$adsHeight;
    
    			$ori = str_replace($val , $$make_ads_var,$ori);
    
    		}//end if  
    	}
    	return $ori;
    }//edn function
    Open Blocked website
    Open Blocked Website
    Knowledge Is Knowing That A Tomato Is A Fruit,
    Wisdom Is Not Putting It In A Fruit Salad.

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably going to need to find your web server (e.g Apache) error log to see what the internal server error is.
    It's odd that a PHP error would cause an internal server error though, normally if there's a problem with your PHP the error would either be displayed or written to a php_errors log file depending on how PHP is configured.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •