澳门新葡亰平台游戏网站php中常用字符串处理代码片段整理

天涯论坛情报小偷1.htmlheadmeta “Refresh” content=”60″META
HTTP-EQUIV=”Pragma” CONTENT=”no-cache”meta “Content-Type”
content=”text/html”;
charset=”??????”title腾讯网_信息抓取程序/title/headbodycenterimg
src=”pic.gif”/center?$host=”127.0.0.1″; // MYSQL 主机名$namesql=”????”;
// MYSQL 顾客名$passsql=”????”; // MYSQL 密码$lib=”news”; //
数据库名$table=”news”; // 数据库表名$filename=””; //
抓取的资源音信页$keytop=”新闻起头”; // 新闻早前主要词$keybottom=”音讯结束”;
//
音信甘休关键词$conn=mysql_澳门新葡亰平台游戏网站,connect($host,$namesql,$passsql);mysql_select_db($lib,$conn);$fp=fopen($filename,”r”,1);$flag=0;
$add=””; $found=0; $end=0; $i=0;
$temp[4]=””;while(!$end==1){while(!$flag==1){$word=fgetc($fp);$add=$add.$word;if($word==”
and strlen($add)==1){ $flag=0; }if($word==” and strlen($add)!=1){
$flag=1; $add=substr($add,0,strlen($add)-1); }if($word==”){ $flag=1; }
}if(strchr($add,$keytop)){ $found=1; }if(strchr($add,$keybottom)){
$found=0; $end=1; }if(((strchr($add,”)==True and
strchr($add,’href’)==True) or strchr($add,”)==False) and $found==1){
$text[$i]=$add; $i++; } if($word==” and $flag==1){ $add=$word;
$flag=0; } else { $add=””; $flag=0; }
}fclose($fp);for($i=1;$isizeof($text)-1;$i+=5){
$temp[1]=$text[$i+1]; $temp[2]=$text[$i+2];
$temp[3]=$text[$i+3]; $temp[4]=$text[$i+4];$ins=”select * from
$table where TITLE=’$temp[3]'”;$list=mysql_query($ins,$conn);
@$count=mysql_num_rows($list);if($count==0){$ins=”insert into
$table(TYPE,URL,TITLE,DATE) values
(‘$temp[1]’,’$temp[2]’,’$temp[3]’,’$temp[4]’)”;$list=mysql_query($ins,$conn);
} }mysql_close($conn);?/body/html2.? $handle = fopen(“”,”r”); $sign =
0; while(!feof($handle卡塔尔(قطر‎State of Qatar { $message = fgets($handle,512卡塔尔国; if($sign == 1卡塔尔(قطر‎{ print(“$message”卡塔尔(قطر‎; } if(ereg(“音讯起首”,$message,$result卡塔尔(قطر‎State of Qatar { $sign =
1; } else if(ereg(“新闻甘休”,$message,$result卡塔尔卡塔尔(قطر‎ { $sign = 0; } }
fclose($handle卡塔尔国; ?

移除 HTML 标签
复制代码 代码如下:
$text = strip_tags($input, “”);

上边包车型大巴函数重若是利用了strip_tags,具体的运用说明参照他事他说加以考察。
  重回 $start 和 $end 之间的文件
复制代码 代码如下:
function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return ”;
}

  将url调换到链接
复制代码 代码如下:
$url = “Jean-Baptiste Jung ()”;
$url = preg_replace(“#”,
‘$0’, $url);

  切分字符串为1四十多个字符
复制代码 代码如下:
function split_to_chunks($to,$text){
$total_length = (140 – strlen($to));
$text_arr = explode(” “,$text);
$i=0;
$message[0]=””;
foreach ($text_arr as $word){
if ( strlen($message[$i] . $word . ‘ ‘) <= $total_length ){
if ($text_arr[count($text_arr)-1] == $word){
$message[$i] .= $word;
} else {
$message[$i] .= $word . ‘ ‘;
}
} else {
$i++;
if ($text_arr[count($text_arr)-1] == $word){
$message[$i] = $word;
} else {
$message[$i] = $word . ‘ ‘;
}
}
}
return $message;
}

  删除字符串中的U大切诺基L
复制代码 代码如下:
$string =
preg_replace(‘/b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]/i’,
”, $string);

  将字符串转成SEO友好的字符串
复制代码 代码如下:
function slug($str){
$str = strtolower(trim($str));
$str = preg_replace(‘/[^a-z0-9-]/’, ‘-‘, $str);
$str = preg_replace(‘/-+/’, “-“, $str);
return $str;
}

  解析 CSV 文件
复制代码 代码如下:
$fh = fopen(“contacts.csv”, “r”);
while($line = fgetcsv($fh, 1000, “,”)) {
echo “Contact: {$line[1]}”;
}

  字符串寻找
复制代码 代码如下:
function contains($str, $content, $ignorecase=true){
if ($ignorecase){
$str = strtolower($str);
$content = strtolower($content);
}
return strpos($content,$str) ? true : false;
}

  检查字符串是还是不是以有个别串起来
复制代码 代码如下:
function String_Begins_With($needle, $haystack {
return (substr($haystack, 0, strlen($needle))==$needle);
}

  从字符串中领取email地址
复制代码 代码如下:
function extract_emails($str){
// This regular expression extracts all emails from a string:
$regexp =
‘/([a-z0-9_.-])+@(([a-z0-9-])+.)+([a-z0-9]{2,4})+/i’;
preg_match_all($regexp, $str, $m);

return isset($m[0]) ? $m[0] : array();
}

$test_string = ‘This is a test string…

test1@example.org

Test different formats:
test2@example.org;
foobar

strange formats:
test5@example.org
test6[at]example.org
test7@example.net.org.com
test8@ example.org
test9@!foo!.org

foobar
‘;

print_r(extract_emails($test_string));

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图