草庐IT

string.format

全部标签

php - mysqli_real_escape_string() 和 mysql_real_escape_string() 的区别

我已经阅读了无数文章,但想知道是否有人可以通俗易懂地向我解释其中的区别?我知道它们既可以防止sql注入(inject)又可以保证安全。但是如果我使用mysqli来运行查询,或者使用老式的my_sql_query方式,那么我使用哪一个真的很重要吗?它们不都是sql函数的包装器吗?为什么下面的代码不起作用?$test="hello,'there";$db->real_escape_string($test);$db->query("INSERTINTOusers(first_name)VALUES('$test')"); 最佳答案 它们

php - PHP 中类似 Python 的 .format()

我有以下数组:$matches[0]="123";$matches[1]="987";$matches[2]="121";以及以下字符串:$result="Myphonenumberis{0}andpolicenumberis{2}";我想根据$matches数组替换{}占位符,以防占位符不匹配时显示任何内容。实现该目标的最佳方法是什么,或者您知道解决我的问题的更好方法吗?(现在我正在构建系统,所以我可以使用任何其他符号代替大括号)更新在python中,这可以使用.format()函数实现。 最佳答案 您可以使用vsprintf来完

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 - 更改错误日志输出格式 : 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 - wordpress formatting.php - 修复双破折号

我对wordpress有疑问,因为它会自动将双“--”转换为长破折号。按照这篇短文中的建议,我找到了一个快速修复方法:Wordpress-Fixdoubledashproblem唯一的问题是,从我的网络浏览器中在线wordpress的仪表板中,我无法弄清楚在哪里/如何找到文件wordpress/wp-includes/formatting.php需要对其进行编辑以解决问题。我还检查了关于wordpress的其他答案,例如howtomodifydateformatinwordpresslistcommentsHowtocustomizeDateFormatinWordpressWordp

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