仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 701|回复: 8
打印 上一主题 下一主题

[学习教程] PHP网页编程之php之str_replace详解

[复制链接]
小女巫 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:11:13 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
通过这段时间的学习实践,对软件开发有了更多新的认识,不在局限于之前的片面性。当然,现在所学到的工具其实并不多,离当一个真正的程序员,还有很大的差距。str_replace

(PHP4,PHP5)
str_replace―Replacealloccurrencesofthesearchstringwiththereplacementstring
Description

mixedstr_replace(mixed$search,mixed$replace,mixed$subject[,int&$count])Thisfunctionreturnsastringoranarraywithalloccurrencesofsearchinsubjectreplacedwiththegivenreplacevalue.
Ifyoudontneedfancyreplacingrules(likeregularexpressions),youshouldalwaysusethisfunctioninsteadofpreg_replace().
Parameters

Ifsearchandreplacearearrays,thenstr_replace()takesavaluefromeacharrayandusesthemtosearchandreplaceonsubject.Ifreplacehasfewervaluesthansearch,thenanemptystringisusedfortherestofreplacementvalues.Ifsearchisanarrayandreplaceisastring,thenthisreplacementstringisusedforeveryvalueofsearch.Theconversewouldnotmakesense,though.
Ifsearchorreplacearearrays,theirelementsareprocessedfirsttolast.

searchThevaluebeingsearchedfor,otherwiseknownastheneedle.Anarraymaybeusedtodesignatemultipleneedles.
replaceThereplacementvaluethatreplacesfoundsearchvalues.Anarraymaybeusedtodesignatemultiplereplacements.
subjectThestringorarraybeingsearchedandreplacedon,otherwiseknownasthehaystack.
Ifsubjectisanarray,thenthesearchandreplaceisperformedwitheveryentryofsubject,andthereturnvalueisanarrayaswell.
countIfpassed,thiswillbesettothenumberofreplacementsperformed.
ReturnValues

Thisfunctionreturnsastringoranarraywiththereplacedvalues.
Changelog


VersionDescription5.0.0Thecountparameterwasadded.4.3.3Thebehaviourofthisfunctionchanged.Inolderversionsabugexistedwhenusingarraysasbothsearchandreplaceparameterswhichcausedemptysearchindexestobeskippedwithoutadvancingtheinternalpointeronthereplacearray.ThishasbeencorrectedinPHP4.3.3,anyscriptswhichreliedonthisbugshouldremoveemptysearchvaluespriortocallingthisfunctioninordertomimictheoriginalbehavior.4.0.5Mostparameterscannowbeanarray.Examples


Example#1Basicstr_replace()examples
再现理想 该用户已被删除
9#
发表于 2015-3-20 10:00:42 | 只看该作者
为了以后维护的方便最好是代码上都加上注释,“予人方便,自己方便”。此外开发文档什么的最好都弄齐全。我觉得这是程序员必备的素质。虽然会消耗点很多的时间。但是确实是非常有必要的。
老尸 该用户已被删除
8#
发表于 2015-3-13 02:07:18 | 只看该作者
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
海妖 该用户已被删除
7#
发表于 2015-3-6 13:23:26 | 只看该作者
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
乐观 该用户已被删除
6#
发表于 2015-2-19 05:15:28 | 只看该作者
为了以后维护的方便最好是代码上都加上注释,“予人方便,自己方便”。此外开发文档什么的最好都弄齐全。我觉得这是程序员必备的素质。虽然会消耗点很多的时间。但是确实是非常有必要的。
飘灵儿 该用户已被删除
5#
发表于 2015-2-6 23:57:46 | 只看该作者
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
变相怪杰 该用户已被删除
地板
发表于 2015-1-31 21:35:40 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
柔情似水 该用户已被删除
板凳
发表于 2015-1-24 06:03:34 | 只看该作者
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
透明 该用户已被删除
沙发
发表于 2015-1-18 21:54:04 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-28 12:22

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表