PHP正则表达式匹配网页中的Url、Sign和From值
在PHP中,你可以使用正则表达式来匹配以上网页中的Url、Sign和From的值。以下是一个示例代码:
<?php
// 定义要匹配的字符串
$html = '<script>const Url = 'zoeRqoseFHH8OO0OOHroOBfOO0OOdtjuhplNNQ6RxdRxzOO0OOXO000OGeKvPgEdtt8nj0V2tts6gK4E';
const Sign = 'a8c307f15783007d6716f72ff5cdd3d9';
const From = 'wnapi';
const posterList = [
'https://img.tgl.qq.com/cover/20230623/5e115db7fee3c92df9bee34932ddad43_1687457419.jpg',
'https://img.tgl.qq.com/cover/20230623/b59dd0125ed37940dcf50ac27ecc9358_1687457439.jpg',
'https://img.tgl.qq.com/cover/20230623/7ebbdeb2d83481395c501a0f051f3001_1687457456.jpg',
'https://img.tgl.qq.com/cover/20230623/9acf313b8df356db0a705e12b34ae58a_1687457477.jpg',
'https://img.tgl.qq.com/cover/20230623/ce113c137e270deb7adebaa5987049af_1687457497.jpg',
];
</script>';
// 使用正则表达式匹配Url、Sign和From的值
preg_match('/const Url = '(.*?)';/', $html, $urlMatches);
preg_match('/const Sign = '(.*?)';/', $html, $signMatches);
preg_match('/const From = '(.*?)';/', $html, $fromMatches);
// 提取匹配结果
$url = $urlMatches[1];
$sign = $signMatches[1];
$from = $fromMatches[1];
// 输出结果
echo 'Url: ' . $url . '<br>';
echo 'Sign: ' . $sign . '<br>';
echo 'From: ' . $from . '<br>';
?>
在上述代码中,我们使用了preg_match函数和正则表达式来匹配字符串中的Url、Sign和From的值。preg_match函数的第一个参数是正则表达式,第二个参数是要匹配的字符串,第三个参数是用于存储匹配结果的数组。正则表达式中的(.*?)表示匹配任意字符,并使用非贪婪模式。通过提取匹配结果的第一个元素,我们可以得到Url、Sign和From的值。最后,我们使用echo语句将结果输出到页面上。
原文地址: https://www.cveoy.top/t/topic/peth 著作权归作者所有。请勿转载和采集!