草庐IT

match_content

全部标签

php - 为什么 preg_match_all() 会多次创建相同的答案?

以下代码从推文中提取#hashtags并将它们放入变量$matches中。$tweet="thishasa#hashtaga#badhash-taganda#goodhash_tag";preg_match_all("/(#\w+)/",$tweet,$matches);var_dump($matches);有人可以向我解释为什么以下结果有2个相同的数组,而不是只有1个吗?array(2){[0]=>array(3){[0]=>string(8)"#hashtag"[1]=>string(8)"#badhash"[2]=>string(13)"#goodhash_tag"}[1]=>a

php - Twilio PHP API 库 : Warning: file_get_contents(): SSL operation failed with code 1

我通过composer("twilio/sdk":"~3.12")安装了官方TwilioPHPAPI库。当我尝试通过测试凭证使用API(例如发送短信)时出现错误:Warning:file_get_contents():SSLoperationfailedwithcode1.OpenSSLErrormessages:error:14090086:SSLroutines:SSL3_GET_SERVER_CERTIFICATE:certificateverifyfailedin..vendor/twilio/sdk/Services/Twilio/HttpStream.phpline62如果

php - 警告 : preg_match(): Compilation failed: unrecognized character after (? 或 (?-

我有一个以前的程序员编写的代码,一个抛出编译错误的正则表达式preg_match:$regex_t="/".$op."(?\\>[^".$op.$cl."]+)*".$cl."/s";preg_match($regex_t,$text,$inner);我收到的警告是:Warning:preg_match():Compilationfailed:unrecognizedcharacterafter(?or(?-atoffset4另外,我想提一下var_dump($regex_t)的值是:string'/\{(?\>[^\{\}]+)*\}/s'(length=21)

php - file_get_contents( - 修复相对 url

我正在尝试向用户显示一个网站,该网站是使用php下载的。这是我正在使用的脚本:到目前为止,除了str_replace函数的一些主要问题外,该脚本还算不错。问题来自相对网址。如果我们在我们制作的名为john.php的页面上使用一只猫的图像(像这样:)。它是一个png,正如我所见,它可以使用6个不同的url放置在页面上:1.src="//www.stackoverflow.com/cat.png"2.src="http://www.stackoverflow.com/cat.png"3.src="https://www.stackoverflow.com/cat.png"4.src="so

php - 使用 php file_get_content 函数发送参数

亲爱的,我如何使用phpfile_get_content函数发送参数。$id='123';$name='blah';$response=file_get_contents('http://localhost/abc/abc.php?id=$id&name=$name');echo$response;我需要将$id和name值发送到abc.php页面。这里传递的值不起作用。我也查了一下?id="$id"&name="$name"值。它也不起作用。但是straite参数works.say-$response=file_get_contents('http://localhost/abc/a

php - file_get_contents() 将 UTF-8 转换为 ISO-8859-1

我正在尝试从yahoo.com获取搜索结果.但是file_get_contents()将UTF-8字符集(雅虎使用的字符集)内容转换为ISO-8859-1。尝试:$filename="http://search.yahoo.com/search;_ylt=A0oG7lpgGp9NTSYAiQBXNyoA?p=naj%C5%A1%C5%A5astnej%C5%A1%C3%AD&fr2=sb-top&fr=yfp-t-701&type_param=&rd=pref";echofile_get_contents($filename);脚本为header('Content-Type:text/

PHP Header Content-Disposition : attachment forces . php 文件或内联

我想从我的网站下载一个.mp3文件,但在使用此代码时,它会在Firefox和Safari中强制使用.php。但在chrome中,它会将文件强制发送为内联文件并在页面上播放。我怎样才能让他们真正下载.mp3文件?$track=$_SERVER['QUERY_STRING'];if(file_exists("/home/user/gets/".$track)){header("Content-Type:audio/mpeg");header('Content-Length:'.filesize($track));header('Content-Disposition:attachment;

php - 使用 preg_match 检查字符串是否仅包含 A-Z、a-z 和 -(破折号)字符

这个问题在这里已经有了答案:Needaregexthatwillcheckifthestringonlyconsistlettersa-zandnumbersandunderscore(_)andhyphen(-)(5个答案)关闭9年前。我试过:print_r(preg_match("[A-Za-z\\-]",$str));我越来越假了。我不太擅长正则表达式,但它似乎适用于http://regexpal.com/我是不是漏掉了什么?编辑:例如$str=zREBsZtyvw

php - preg_match编译失败:字符类中的无效范围

这个问题已经有了答案:preg_match():Compilationfailed:invalidrangeincharacterclassatoffset4答我使用laravel作为框架,并尝试使用自己的preg_match函数来验证表单。以下是我的代码:Validator::extend('alpha_num_spaces',function($attribute,$value){returnpreg_match('/^([-a-z0-9_-\s])+$/i',$value);});现在,我已经在生产服务器上运行了这个程序,它运行得很好,但是,在我的本地计算机上,我收到:preg_

php - 将 array_key_exists 与 preg_match 结合使用

我正在尝试根据模式确定一个或多个匹配项是否存在于数组中,数组的例子:Array([author_id]=>1[channel_id]=>1[site_id]=>1[entry_id]=>6[url_title]=>test_title_with_file2[title]=>TestTitlewithfile[field_id_1_directory]=>1[field_id_4_directory]=>1[submit]=>Submit[entry_date]=>1278219110)我想确定field_id_x_directory键或多个键是否存在,如果存在,则循环遍历每个键并运行一