strip_tags help

Discussion in 'PHP' started by izlik, Dec 20, 2007.

  1. #1
    Hello.

    I have this code bellow that in it is supposed to remove <img> & <span>
    tags of anyting that's enterd into the database, if i wanna also strip </span>, how do i do that ? :/

    i would appriciate any help.



    			$string_ahref = $match[0];
    			//echo "string = ".$string_ahref;
    
    
    			$substr = substr($string_ahref,0,355);
    
    			$trimed = strip_tags($substr,"<img>");
    			$trimed = trim($trimed);
    			//echo "strip".$trimed;
    			$trimed = substr($trimed, 0 , -4);
    
    			$len = strlen($trimed);
    			//echo "length".$len."<br>";
    			$image_name = substr($trimed,28,($len-25));
    			//echo "<br><br>imname= '".$image_name."'<br>";
    
    			preg_match("/<span class=\"nametext\".*>?<\/span>/is",$buff,$match_name);
    
    			//echo "name= ".$match_name[0];
    
    			if(empty($image_name))
    			{
    				$img_name = substr($match_name[0],100,600);
    				$img  = strip_tags($img_name,"<img>");
    
    				//echo "strip-->".$img."<--";
    				$img = trim($img);
    
    
    				$len = strlen($img);
    				//echo "length".$len."<br>";
    
    				$image_name = substr($img,10,($len-25));
    
    				$image_name = trim($image_name);
    				//echo "ooo".$img."000";
    				//echo "Image = ->".$image_name."<--";
    			}
    
    
    
    			if(substr($image_name,0,10)=="<img src=\"")
    			{
    				$third_name = substr($image_name,10,strlen($image_name));
    				//echo "third = ".$third_name;
    				$image_name = $third_name;
    			}
    
    			//echo "<br><br>imname= '".$image_name."'<br>";
    			$subname    = substr($match_name[0],0,200);
    			$name       = strip_tags($subname,"<span>");
    			$name = trim($name);
    
    			$len_name   = strlen($name);
    		//	echo $len_name;
    			$name_final = substr($name,23,($len_name-30));
    
    			$arr = array("name"=>$name_final,"imagepath"=>$image_name);
    
    			//exit();
    		}
    		fclose($handle);
    		ini_restore('max_execution_time');
    		ini_restore('default_socket_timeout');
    
    		$dname = $arr['name'];
    		$img = $arr['imagepath'];
    
    
    $query = "INSERT INTO fc_users VALUES ('','$id','$dname','','','','','','','','$img','','','','','".date("U")."','0')";
    mysql_query($query) or die(mysql_error());
    
    
      }
    }
    PHP:
     
    izlik, Dec 20, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Can you please tell me what this exactly does (my eyes hurt when I looked at it):

    
    $string_ahref = $match[0];
                //echo "string = ".$string_ahref;
    
    
                $substr = substr($string_ahref,0,355);
    
                $trimed = strip_tags($substr,"<img>");
                $trimed = trim($trimed);
                //echo "strip".$trimed;
                $trimed = substr($trimed, 0 , -4);
    
                $len = strlen($trimed);
                //echo "length".$len."<br>";
                $image_name = substr($trimed,28,($len-25));
                //echo "<br><br>imname= '".$image_name."'<br>";
    
                preg_match("/<span class=\"nametext\".*>?<\/span>/is",$buff,$match_name);
    
                //echo "name= ".$match_name[0];
    
                if(empty($image_name))
                {
                    $img_name = substr($match_name[0],100,600);
                    $img  = strip_tags($img_name,"<img>");
    
                    //echo "strip-->".$img."<--";
                    $img = trim($img);
    
    
                    $len = strlen($img);
                    //echo "length".$len."<br>";
    
                    $image_name = substr($img,10,($len-25));
    
                    $image_name = trim($image_name);
                    //echo "ooo".$img."000";
                    //echo "Image = ->".$image_name."<--";
                }
    
    
    
                if(substr($image_name,0,10)=="<img src=\"")
                {
                    $third_name = substr($image_name,10,strlen($image_name));
                    //echo "third = ".$third_name;
                    $image_name = $third_name;
                }
    
                //echo "<br><br>imname= '".$image_name."'<br>";
                $subname    = substr($match_name[0],0,200);
                $name       = strip_tags($subname,"<span>");
                $name = trim($name);
    
                $len_name   = strlen($name);
            //  echo $len_name;
                $name_final = substr($name,23,($len_name-30));
    
                $arr = array("name"=>$name_final,"imagepath"=>$image_name);
    
                //exit();
            }
    
    PHP:
    Is it just stripping 3 tags out? That could be done in 1 line.

    Peace,
     
    Barti1987, Dec 20, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    i didint code this from the start :( and rebuilding this messes everyting up, soi wanted to add striping of </span> only if possible.

    It's a login script, when someone logins with an ID number it's enterd into the database and strips the tags <img> and <span>, but </span> also needs to be stripped which the coder forgot.

    So i hope someone could help me add stripping of </span>

     
    izlik, Dec 21, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    I dont have time time to rewrite the code, but after this:

    
    $subname    = substr($match_name[0],0,200);
    $name       = strip_tags($subname,"<span>");
    $name = trim($name);
    
    PHP:
    Add:

    
    $subname    = substr($name,0,200);
    $name       = strip_tags($subname,"</span>");
    $name = trim($name);
    
    PHP:
    Peace,
     
    Barti1987, Dec 21, 2007 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5
    thanks! :) i have anoter problem with striping here..
    $img = strip_tags($img_name,"<strip>");

    Where <Strip> is above, how would that look like if i wanted to remove the wierd stuff in hte image bellow

    so it becomes http://theimage.com/efcd0033a74f7344439d3177cde91362.jpg only ?
     
    izlik, Dec 21, 2007 IP