php preg_match 查找一个单词 ia 字符串
我有一个数据库,上面有超过 20,000 个帖子。大多数帖子都有签名:
像这样:
If in my dreams is the only
place i can hould u !
Then i want to sleep forever !!
Me:bb:272F9F64
所以我想打印我的数据库中包含签名(Me:PIN:272F9F64)的所有帖子,
所有这些签名都以(PIN:或PIN)开头,并且它们是8数字和字母。
我用这个代码来打印它们,但它不起作用
$get_tit = $db->query("select id,name from brd limit 1000");
while($th=$db->fetch($get_tit)){
if (preg_match("/PIN:[0-9a-zA-Z]+/", $th['name'])) {
echo $th['name']."<br>";
}
}
更新**
这个循环代码抛出数据库并删除帖子中的任何签名,
$get_tit = $db->query("SELECT id, name FROM brd LIMIT 1000");
echo 'Results Found :'.mysql_num_rows($get_tit).'<br /><br />';
while($th=$db->fetch($get_tit)){
$result = mysql_query("UPDATE brd SET name=LEFT(name,LENGTH(name)-12) WHERE name REGEXP 'PIN:[0-9a-zA-Z]{8}$' and id='$th[id]'") or die(mysql_error());
}
但它不起作用签名仍然有
任何帮助伙计们
Bbway
i have a database with more than 20.000 posts on it. most of the posts have a signature:
like this one :
If in my dreams is the only
place i can hould u !
Then i want to sleep forever !!
Me:bb:272F9F64
so i want to print all the posts insde my database who contain signatures like (Me:PIN:272F9F64 )
all those signatures are starting with ( PIN: or PIN ) and they are 8 digits numbers and alphabit.
i used this code to print them but it is not working
$get_tit = $db->query("select id,name from brd limit 1000");
while($th=$db->fetch($get_tit)){
if (preg_match("/PIN:[0-9a-zA-Z]+/", $th['name'])) {
echo $th['name']."<br>";
}
}
UPDATED **
this code for loop throw the database and delete any signature inside the post
$get_tit = $db->query("SELECT id, name FROM brd LIMIT 1000");
echo 'Results Found :'.mysql_num_rows($get_tit).'<br /><br />';
while($th=$db->fetch($get_tit)){
$result = mysql_query("UPDATE brd SET name=LEFT(name,LENGTH(name)-12) WHERE name REGEXP 'PIN:[0-9a-zA-Z]{8}
but it is not working the signature still there
any help Guys
Bbway
and id='$th[id]'") or die(mysql_error());
}
but it is not working the signature still there
any help Guys
Bbway
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这个查询:
Try this query:
尝试将 m 修饰符添加到您的预匹配中。它打开了多行模式。
Try to add m modifier to your preg match. It's turn on multiline mode.
这可以在 MySQL 中轻松完成:
不过,您确定
name
是包含帖子的字段吗?我不知道你的数据库是如何设计的,但就我个人而言,我将name
作为用户名,将content
作为帖子的内容。确保您拥有正确的字段名称。This can be done really easily within MySQL:
Are you sure
name
is the field that has the post in it, though? I don't know how you have your database designed, but personally I'd havename
as the name of the user, andcontent
as the content of the post. Make sure you have the right field name.