在函数中的特定位置替换字符串在PHP中? [英] Replace string at particular position in function In PHP?
本文介绍了在函数中的特定位置替换字符串在PHP中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的函数中将一些动态数据打印到这样的函数中传递字符串。
我的函数
函数mysql_funX_Repeter($ query,$ itemtemplet)
{
$ this-> mysql_funX_connect();
$ result = mysql_query($ query)或 die( 重复查询错误。);
if (!$ result)
{
$ message = ' 错误:'。 mysql_error();
return $ message ;
}
else
{
$ newtempelt = str_replace( Eval,' < span class =code-string> $ row',$ itemtemplet);
while ($ row = mysql_fetch_array($ result))
{
echo $ newtempelt ;
}
}
}
在函数中传递值
< ul >
<?php
$ rptvalue = < li>< a href =''> Eval [ '名称']< / A>< /锂>中跨度>;
$ myFun-> mysql_funX_Repeter( 从tbldemo中选择名称,$ rptvalue);
?>
< / ul >
我的输出
- $ row ['name']
- $ row ['name']
- $ row ['name']
我想输出
- raj
- ram
- prince
但它只显示变量但不显示数据库值。如何解决这个问题... !!!
解决方案
query,
itemtemplet)
{
这 - > mysql_funX_connect();
I want to Print some dynamically data from my function to passing string in function like this.
My Function
function mysql_funX_Repeter($query,$itemtemplet)
{
$this->mysql_funX_connect();
$result = mysql_query($query) or die("Repeter Query Error.");
if (!$result)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{
$newtempelt = str_replace("Eval", '$row', $itemtemplet);
while ($row = mysql_fetch_array($result))
{
echo $newtempelt;
}
}
}
Passing Value In Function
<ul>
<?php
$rptvalue="<li><a href=''>Eval['name']</a></li>";
$myFun->mysql_funX_Repeter("Select name from tbldemo",$rptvalue);
?>
</ul>
My Output
- $row['name']
- $row['name']
- $row['name']
I want Output
- raj
- ram
- prince
But it's Show me only variable but not show it's database value. How to solve this...!!!
解决方案
query,
itemtemplet) {
this->mysql_funX_connect();
这篇关于在函数中的特定位置替换字符串在PHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文