Home > Backend Development > PHP Tutorial > 关于随机从数据库读取数据并逐个替换的有关问题

关于随机从数据库读取数据并逐个替换的有关问题

WBOY
Release: 2016-06-13 10:25:09
Original
855 people have browsed it

关于随机从数据库读取数据并逐个替换的问题
有一篇文字$str

我现在需要替换这篇文字里的关键词$key

全部替换是

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//rand()随机读取数据//.....//.....$str=str_ireplace({key},".$Rs["title"]"",$str);echo $str;
Copy after login


如何随机逐个替换,才能做到不重复的呢?




------解决方案--------------------
既然是“随机”,就不能避免重复
------解决方案--------------------
随机,逐个?听起来有点矛盾哦
------解决方案--------------------
描述的模模糊糊的。 你让key随机不就行了。
------解决方案--------------------
如果$key是数组,$k = array_rand($key,1);用$k进行替换
------解决方案--------------------
for($i=0;$i $string=str_ireplace("你好","你们好$i",$string);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template