on-topic
如何检查PHP中的文本中是否包含链接?
我有如下数据库表格式。
+------------------+
| id | posts | tag |
+------------------+
| 1 | text 1| 0 | //no links
| 2 | text 2| 1 | //contains links
基本上,我想验证提交的条目是否包含链接,如果包含,tag
列的值将为1
。
有人可以帮我正确编码上面的示例吗?当前这是我的PHP:
include 'function.php';
$text= $_POST['text'];
//if $text contains a url then do this function
postEntryWithUrl($text);
//else here
postEntry($text);
参考方案
您可以使用stristr()
$has_link = stristr($string, 'http://') ?: stristr($string, 'https://');
http://php.net/manual/en/function.stristr.php
或preg_match()
preg_match('/(http|ftp|mailto)/', $string, $matches);
var_dump($matches);
https://www.php.net/manual/en/function.preg-match.php
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…
PHP-将日期插入日期时间字段 - php我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数
PHP-全局变量的性能和内存问题 - php假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…
php-casperjs获取内部文本 - php我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…
php ziparchive类源代码 - phpImprove this question 我如何获取ziparchive类本身的源代码。 参考方案 假设您在谈论PHP ZipArchive class:下载PHP source code并查找适当的文件。如果您希望源代码是PHP代码,您可能会感到失望,因为源代码是用C语言编写的。或者,也可以在PHP Github Development Reposito…