草庐IT

string-split

全部标签

php - 我应该使用 mysqli_real_escape_string 还是应该使用准备好的语句?

这个问题在这里已经有了答案:HowcanIpreventSQLinjectioninPHP?(27个答案)关闭9年前。我应该使用mysqli_real_escape_string还是应该使用准备好的语句?我现在看到了一个解释准备语句的教程,但我看到它们做与mysqli_real_escape_string相同的事情,但它使用更多行准备好的报表有什么好处吗?您认为最好的使用方法是什么?

php - 如何通过 PHP 和 String 函数获取所有 TD 值

这个问题在这里已经有了答案:ExtractdatafromHTMLtablerowcolumn(3个答案)关闭2年前。我需要从TD获取数据,变量是一个字符串:$string='abcdefghi';echo$td_num=substr_count($string,'');for($i=0;$i".$i."";$first_td[$i]=strpos($string,'');echo'Firstposition:'.$first_td[$i]."";$last_td[$i]=strpos($string,"");echo'Lastposition:'.$last_td[$i]."";$t

php - PHP 中的正则表达式 : find the first matching string

我想在非常非常长的文本中找到第一个匹配的字符串。我知道我可以使用preg_grep()并获取返回数组的第一个元素。但是如果我只需要第一场比赛(或者我知道提前只有一场比赛),这样做效率不高。有什么建议吗? 最佳答案 preg_match()?preg_match()returnsthenumberoftimespatternmatches.Thatwillbeeither0times(nomatch)or1timebecausepreg_match()willstopsearchingafterthefirstmatch.preg_m

PHP preg_split 忽略转义序列

我怎样才能一个一个地拆分字符串但忽略转义字符?在我的例子中,我有字符串:-\ntest\rtest\n我希望它是这样的:-Array([0]=>\n[1]=>t[2]=>e[3]=>s[4]=>t[5]=>\r[6]=>t[7]=>e[8]=>s[9]=>t[10]=>\n)有人说用preg_split,但我对正则表达式了解不多。 最佳答案 反斜杠需要在RegEx中转义。当引用一个实际的反斜杠时,你需要一系列的三个\\\正则表达式匹配preg_match_all("/\\\?[^\\\]/",$str,$matches);现场演示代

php - 更改错误日志输出格式 : ini_set ('error_append_string' , 'string' ) 和 ini_set ('error_prepend_string' , 'string' ) 什么都不做

这是我告诉php要做的:希望我能在一个文件中报告所有错误,在消息前加上“PRE”,在消息后加上“APP”。(我的目标是把PRE和APP做成/n/r什么的。。。)但是我的报错日志是这样的:[14-May-201300:16:26]PHPNotice:Undefinedvariable:nonexistentvariablein/home/www/dir/index.phponline14[14-May-201300:16:28]PHPNotice:Undefinedvariable:nonexistentvariablein/home/www/dir/index.phponline14没

PHP PDO : Charset=UTF8 : An invalid keyword charset was specified in the dsn string

我正在使用sqlsrv驱动程序连接到带有PDO的MSSQL服务器。PHP版本为5.3.24。工作连接如下所示:$dsny="sqlsrv:Server=xx1;Database=xx2";$usery='xx3';$passwordy='xx4';$dbhy=newPDO($dsny,$usery,$passwordy);**但是我需要设置字符,然后我试试这个:$dsny="sqlsrv:Server=xx1;Database=xx2;charset=utf8";$usery='xx3';$passwordy='xx4';$dbhy=newPDO($dsny,$usery,$passw

php - 可捕获的 fatal error : Object of class PDOStatement could not be converted to string in line 114

这个问题在这里已经有了答案:returnonevaluefromdatabasewithmysqlphppdo(3个答案)关闭23天前。我正在尝试向我的数据库中添加一些数据,但我在第114行的/var/www/mandje.php中收到错误Catchablefatalerror:ObjectofclassPDOStatementcouldnotbeconvertedtostringin/var/www/mandje.php。这是我正在使用的代码:foreach($_SESSION["cart"]as$id=>$value){$query=$db->query('SELECT*FROMP

php - 通知消息 : Array to string conversion

我是codeigniter和php的初学者,我正面临这个问题APHPErrorwasencounteredSeverity:NoticeMessage:Undefinedvariable:queryFilename:inc/header_main_view.phpLineNumber:175APHPErrorwasencounteredView:id_task;?>name;?>20%20%Completeindex.php/dashboard/g_tasks_menu">ViewalltasksControllerpublicfunctionget_todo($id=null){$t

PHP:如何用破折号和括号之间的所有内容拆分字符串。 (preg_split 或 preg_match)

几天来我一直在思考这个问题,但似乎没有得到想要的结果。例子:$var="SomeWords-OtherWords(MoreWords)Dash-Binded-Word";期望的结果:array([0]=>SomeWords[1]=>OtherWords[2]=>MoreWords[3]=>Dash-Bound-Word)我能够使用preg_match_all使这一切正常工作,但随后“Dash-Bound-Word”也被分解了。尝试将它与周围的空格匹配是行不通的,因为它会破坏除破折号之外的所有单词。我使用的preg_match_all语句(它也分解了破折号绑定(bind)的词)是这样的:

php - 是否有匹配 "string"和 "Object that implements __toString()"的 native 接口(interface)?

我们有实现__toString()的对象:classFoo{publicfunction__toString(){return'bar';}}然后我们有返回string或实现__toString()的对象的函数,如上面的示例。当对字符串使用返回类型string时当然有效:functiongetString():string{return'Works!';}Foo类型的返回对象不起作用,因为它不是字符串:functiongetString(Foo$foo):string{return$foo;//FatalTypeError!}是否有任何PHP接口(interface)可用于类型提示st