php preg_match 查找一个单词 ia 字符串

发布于 2025-01-06 17:04:24 字数 997 浏览 4 评论 0原文

我有一个数据库,上面有超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧瑾黎汐 2025-01-13 17:04:25

尝试这个查询:

SELECT id, name, FROM brd WHERE name REGEXP 'PIN:?[0-9a-zA-Z]{8}
 LIMIT 1000

Try this query:

SELECT id, name, FROM brd WHERE name REGEXP 'PIN:?[0-9a-zA-Z]{8}
 LIMIT 1000
浊酒尽余欢 2025-01-13 17:04:25

尝试将 m 修饰符添加到您的预匹配中。它打开了多行模式。

Try to add m modifier to your preg match. It's turn on multiline mode.

柒七 2025-01-13 17:04:24

这可以在 MySQL 中轻松完成:

SELECT id, name FROM brd WHERE name REGEXP 'PIN:[0-9a-zA-Z]+

不过,您确定 name 是包含帖子的字段吗?我不知道你的数据库是如何设计的,但就我个人而言,我将 name 作为用户名,将 content 作为帖子的内容。确保您拥有正确的字段名称。

LIMIT 1000

不过,您确定 name 是包含帖子的字段吗?我不知道你的数据库是如何设计的,但就我个人而言,我将 name 作为用户名,将 content 作为帖子的内容。确保您拥有正确的字段名称。

This can be done really easily within MySQL:

SELECT id, name FROM brd WHERE name REGEXP 'PIN:[0-9a-zA-Z]+

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 have name as the name of the user, and content as the content of the post. Make sure you have the right field name.

LIMIT 1000

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 have name as the name of the user, and content as the content of the post. Make sure you have the right field name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文