Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从preg_replace中提取数据_Php_Mysql - Fatal编程技术网

Php 如何从preg_replace中提取数据

Php 如何从preg_replace中提取数据,php,mysql,Php,Mysql,我希望能够从preg_replace函数或str_replace函数获取数据。例如,我想转换任何以@开头的字符串。但我想提取以@开头的字符串并将其放入我的数据库中!那么我如何才能提取以@开头的特定单词呢 这是我的密码: $string = "@james is awespome"; $convert = preg_replace('@','<a href="#">@$1</a>','$string'); mysql_query( insert stuff); $st

我希望能够从preg_replace函数或str_replace函数获取数据。例如,我想转换任何以@开头的字符串。但我想提取以@开头的字符串并将其放入我的数据库中!那么我如何才能提取以@开头的特定单词呢

这是我的密码:

$string = "@james is awespome";

$convert = preg_replace('@','<a href="#">@$1</a>','$string');

mysql_query( insert stuff);
$string=“@james is awespome”;
$convert=preg_replace('@',''$string');
mysql_查询(插入内容);
我希望能够在数据库中插入@james或james,请改用:

<?php
$string = "@james is awespome";
$convert = preg_replace('/(@.*?)\s.*/','$1', $string);
print $convert;

试试
preg\u match
。这个问题与mysql和mysqli有什么关系?@YourCommonSense im使用mysqli\u查询将数据插入我的数据库fyi@elclanrs我希望它能起作用这就是答案!我打赌您正在使用插入的信息显示在HTML页面上。那么为什么它没有用[html]标记呢?
$string = "@james is awespome";
preg_match('/@([A-Za-z0-9_]{1,15})/', $string, $convert); 
//matches @<string of length upto 15 chars>
echo $convert[0];
@james