 |
ช่วยแก้ปัญหาเรื่อง regex_pattern หน่อยได้มั๊ยครับ ทำไมมันไม่ยอมส่งค่าไปเก็บใน Array |
|
 |
|
|
 |
 |
|
<?
class ChkLink {
function filter($input,$replace){
$urlAllow = array("http://www.google.com","http://premium.google.com","http://point.google.com"); //Link to Allow Post
$input=str_replace("'", "\"", $input);
$input = stripslashes($input);
$regex_pattern = '/<a href="(.*)">(.*)<\/a>/'; /// ติดปัญหาตรงนี้
preg_match_all($regex_pattern,$input,$matches);
$all_url = $matches[1];
foreach( $all_url as $url ) {
$searchUrlAllow = array_search($url, $urlAllow);
if(empty($searchUrlAllow) && $searchUrlAllow !== 0){
$input = str_replace( $url, $replace, $input);
}
}
return $input;
}
}
?>
(ส่งข้อมูลผ่านทาง input เข้ามา ถ้าส่ง Link มาตัวเดียวไม่มีปัญหาอะไรครับ ถ้าเมื่อไหร่ส่งมากกว่า 1 มันมีปัญหาทันทีเลยครับ ไม่สามารถเช็คได้เลย ไม่ยอมส่งค่าไปเก็บใน Array ให้ กองรวมกันอยู่แค่ Array เดียว)
Tag : PHP, Class Library
|
|
 |
 |
 |
 |
Date :
2010-10-14 13:15:53 |
By :
pichitchaip |
View :
836 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จำทำอะไรครับ?
|
 |
 |
 |
 |
Date :
2010-10-14 13:32:13 |
By :
pjgunner.com |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนโปรแกรมดัก Link ครับ
|
 |
 |
 |
 |
Date :
2010-10-14 13:47:17 |
By :
pichitchaip |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
???????? ไม่เข้าใจครับ
|
 |
 |
 |
 |
Date :
2010-10-14 13:53:23 |
By :
pjgunner.com |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$links= 'Test Link <a href="http://www.google.co.th" class="something">Google Thailand</a> Test <a href="http://www.google.com" class="red">Google Global</a> Test <a href="http://www.test.com/index.php" id="test" class="something">Test dot com index page</a> Test <a href="http://sub.test.com/" class="something">Sub domain of test dot com</a> Test <a href="http://www.test.com/index.php?id=555" class="something">Test dot com with query string</a>';
$results = array();
preg_match_all("/<a href=\"([^\"]+)\"[^>]*>([^<]*)<\/a>/i",$links,$results);
echo print_r($results[1]);
echo "<br />";
echo print_r($results[2]);
แบบนี้หรือเปล่าที่ต้องการ เอาไปต่อเองนะ ถ้าใช่
|
 |
 |
 |
 |
Date :
2010-10-14 14:14:01 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่รู้จะกดขอบคุณสักกี่ครั้ง ถึงจะำพอ ขอบคุณจริงๆครับ
|
 |
 |
 |
 |
Date :
2010-10-14 14:51:29 |
By :
pichitchaip |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2010-10-14 14:55:04 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|