 |
curl กับ preg_match รบกวนดูให้หน่อยค่ะ ว่าอยากจะ preg_match มือใหม่ regular expression ค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
$curl = curl_init('http://sbayjai.com/forum/index.php?board=12.0');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
preg_match("/<a href=\"http://sbayjai.com/forum/index.php?topic\".*a>/", $result, $matches1);
print_r($matches1);
ตอนนี้ติดตรง preg_match จากรูป

อยากให้ preg_match ค้นหาคำว่า "test_curl" ใน http://sbayjai.com/forum/index.php?board=12.0 ถ้าเจอ ให้เก็บ เลขหลัง "topic=67065.0" เก็บเลข 67065.0
รบกวนช่วยดูให้หน่อยค่ะ
ขอบคุณมากค่ะ
Tag : PHP, HTML/CSS, CakePHP
|
|
 |
 |
 |
 |
Date :
2016-02-16 08:53:26 |
By :
sammam |
View :
1934 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
function getTopics($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
preg_match_all("/topic=[0-9]{1,}\.[0-9]{1,}/", $result, $matches, PREG_SET_ORDER);
$array = [];
foreach($matches as $match) {
foreach($match as $val) {
$array[] = str_replace('topic=', '', $val);
}
}
return array_unique($array);
}
|
 |
 |
 |
 |
Date :
2016-02-16 10:03:01 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$str = <<<EOF
<div>Do not match me</div>
<div type="special_type" src="bla"> match me</div>
<a>not me</a>
<div src="blaw" type="special_type" > match me too</div>
EOF;
$doc = new DOMDocument();
$doc->loadHTML($str);
$selector = new DOMXPath($doc);
$result = $selector->query('//div[@type="special_type"]');
// loop through all found items
foreach($result as $node) {
echo $node->getAttribute('src');
}
น่าจะ Apply ได้ไม่ยาก
|
 |
 |
 |
 |
Date :
2016-02-16 11:02:34 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่า regular นี่เร็วที่สุดแล้วนะครับ
Code (PHP)
<?php
$data = '
<a href="http://sbayjai.com/form/index.php?topic=67065.0">test_curl</a>
<a href="http://sbayjai.com/form/index.php?topic=999.1">xxxxcurl</a>
<a href="http://sbayjai.com/form/index.php?topic=66665.0">test_curl</a>
';
preg_match_all('/\<a[^\?]+\?([^\"]+)\"\s*\>test_curl\<\/a\>/', $data, $match);
echo '<pre>',htmlspecialchars(print_r($match, true)),'</pre>';
if( count($match[0])){
foreach($match[1] as $vl){
preg_match_all('/topic\=([0-9]+\.[0-9]+)/', $vl, $m1);
if(count($m1[1])) echo $m1[1][0], '<br>';
}
}
|
 |
 |
 |
 |
Date :
2016-02-16 11:08:21 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ ได้แล้วค่ะ ใช้ code ตัวนี้ค่ะ
Code (PHP)
<?php
$curl = curl_init('http://sbayjai.com/forum/index.php?board=12.0');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
print_r($matches1);
preg_match_all('/\<a[^\?]+\?([^\"]+)\"\s*\>test_curl\<\/a\>/', $result, $matches1);
echo '<pre>',htmlspecialchars(print_r($matches1, true)),'</pre>';
if( count($matches1[0])){
foreach($matches1[1] as $vl){
preg_match_all('/topic\=([0-9]+\.[0-9]+)/', $vl, $m1);
if(count($m1[1])) echo $m1[1][0], '<br>';
}
}
?>
|
 |
 |
 |
 |
Date :
2016-02-16 13:10:25 |
By :
sammam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอถามอีกหน่อยค่ะ ตามรูปนี้เรียกว่าอะไรกันหรอค่ะ ว่าจะลองหา code มาใส่ในเว็บอะค่ะ ที่เป็นเหมือน Microsoft Word มีเครื่องมือต่างๆอะค่ะ

ขอบคุณมากค่ะ
|
 |
 |
 |
 |
Date :
2016-02-16 13:15:46 |
By :
sammam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียกว่า โปรแกรม text editor มีหลายค่าย ก็ลองเสริชหาดูครับ
แต่ถ้าอยากได้ แบบ thaicreate เซฟหน้าเพจ ลงเครื่องเลยครับ ทดลองเล่นทดลองแกะ เอาเลยครับ
ขออนุญาต mr.win ซักนิด 5555
|
ประวัติการแก้ไข 2016-02-16 13:44:09
 |
 |
 |
 |
Date :
2016-02-16 13:43:35 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
bootstrap-wysiwyg
https://mindmup.github.io/bootstrap-wysiwyg/
ใส่รูปได้ด้วย
แต่ระวังหน่อยแล้วกัน database จะบวม
เพราะมันแปลงรูปเป็น binary string แล้วยัดลง database แบบ text
|
 |
 |
 |
 |
Date :
2016-02-16 13:51:02 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขออนุญาต @mr.win นะค่ะ  
ตอนนี้ทดลองใช้
ของ thaicreate แต่ ติดตรงที่ ไม่มี bbcode.js ทำให้ script ไม่ทำงานใช่ไหมค่ะ
Code (PHP)
<script language="JavaScript" src="bbcode.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
function showimage()
{
document.images.icons.src = icon_urls[document.frmMain.txtDescription.icon.options[document.frmMain.txtDescription.icon.selectedIndex].value];
}
function bbc_highlight(something, mode)
{
something.style.backgroundImage = "url("+(mode ? "/images/bbcode/bbc_hoverbg.gif?v=1001)" : "/images/bbcode/bbc_bg.gif?v=1001)");
}
</script>
<a onclick="surroundText('', '', document.forms.frmMain.txtDescription); return false;" href="javascript:void(0);"><img onmouseover="bbc_highlight(this, true);" title="ตัวหนา" style="margin: 1px 2px 1px 1px; background-image: url("/images/bbcode/bbc_bg.gif?v=1001");" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" height="22" alt="ตัวหนา" src="/images/bbcode/bold.gif?v=1001" width="23" align="bottom" border="0"></a>
<textarea name="txtDescription" rows="25" class="topicSubject" id="txtDescription" style="width:800px;" onkeyup="storeCaret(this);" onclick="storeCaret(this);" onchange="storeCaret(this);" onselect="storeCaret(this);"></textarea>
@mr.win ใจดีแจก bbcode.js ไหมค่ะ   
|
 |
 |
 |
 |
Date :
2016-02-16 15:27:03 |
By :
sammam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
https://www.thaicreate.com/js/bbcode.js
|
 |
 |
 |
 |
Date :
2016-02-16 16:22:28 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของผมเขียนยังมั่ว ๆ อยู่เลยครับ แต่มันยังใช้ได้ เลยไม่คิดจะรื้อ 555+
|
 |
 |
 |
 |
Date :
2016-02-16 18:07:57 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ
Code (PHP)
$data = '
<a href="http://www.rayongcenter.com/forum/index.php/topic,12345.0.html">test_curl</a>
';
preg_match_all('/\<a[^\?]+\/([^\"]+)\"\s*\>test_curl\<\/a\>/', $data, $match);
echo '<pre>',htmlspecialchars(print_r($match, true)),'</pre>';
|
 |
 |
 |
 |
Date :
2016-03-15 11:55:33 |
By :
sammam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|