1. 首页
  2. php

PHP – 字符串

它们是字符序列,例如“PHP支持字符串操作”。

 – 函数参考PHP字符串函数中给出了内置字符串函数

PHP - 字符串

以下是字符串的有效示例

$string_1 = "This is a string in double quotes";
$string_2 = "This is a somewhat longer, singly quoted string";
$string_39 = "This string has thirty-nine characters";
$string_0 = ""; // a string with zero characters

单引号字符串几乎按字面处理,而双引号字符串用其值替换变量以及特别解释某些字符序列。

<?php
   $variable = "name";
   $literally = 'My $variable will not print!\\n';
   
   print($literally);
   print "<br />";
   
   $literally = "My $variable will print!\\n";
   
   print($literally);
?>

这将产生以下结果 –

My $variable will not print!\n
My name will print!\n

字符串长度没有人为限制 – 在可用内存的范围内,你应该能够制作任意长的字符串。

由双引号分隔的字符串(如“this”中所示)由PHP以下两种方式进行预处理 –

  • 以反斜杠(\)开头的某些字符序列将替换为特殊字符
  • 变量名(以$开头)将替换为其值的字符串表示形式。

逃逸序列替换是 –

  • \ n由换行符替换
  • \ r \ n由回车符替换
  • \ t由制表符替换
  • \ $被美元符号本身取代($)
  • \“被一个双引号(”)取代
  • \\由单个反斜杠(\)替换

字符串连接运算符

要将两个字符串变量连接在一起,请使用点(。)运算符 –

<?php
   $string1="Hello World";
   $string2="1234";
   
   echo $string1 . " " . $string2;
?>

这将产生以下结果 –

Hello World 1234

如果我们查看上面的代码,您会看到我们使用了连接运算符两次。这是因为我们必须插入第三个字符串。

在两个字符串变量之间,我们添加了一个带有单个字符的字符串,一个空格,以分隔这两个变量。

使用strlen()函数

strlen()函数用于查找字符串的长度。

让我们找到字符串“Hello world!”的长度。 –

<?php
   echo strlen("Hello world!");
?>

这将产生以下结果 –

12

当知道字符串何时结束很重要时,字符串的长度通常用在循环或其他函数中。(即在循环中,我们希望在字符串中的最后一个字符后停止循环)

使用strpos()函数

strpos()函数用于搜索字符串中的字符串或字符。

如果在字符串中找到匹配项,则此函数将返回第一个匹配项的位置。如果未找到匹配项,则返回FALSE。

让我们看看我们是否可以在字符串中找到字符串“world” –

<?php
   echo strpos("Hello world!","world");
?>

这将产生以下结果 –

 6

如您所见,字符串“world”在我们的字符串中的位置是位置6.它是6而不是7的原因是字符串中的第一个位置是0,而不是1。

原创文章,作者:零久SEO,如若转载,请注明出处:http://www.seo0j.com/320.html

Free Inpatient Drug Rehab Centers Near Me进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注

评论列表(42条)

  • 100% real jordans for cheap 2020年2月23日 上午8:40

    Thanks a lot for providing individuals with remarkably wonderful opportunity to read in detail from this blog. It is often very pleasant plus jam-packed with amusement for me personally and my office friends to search your web site more than 3 times a week to see the fresh items you will have. Not to mention, we’re at all times contented with your magnificent thoughts you give. Selected 4 tips on this page are in truth the best I have had.

  • moncler jackets 2020年2月26日 上午4:39

    I simply desired to say thanks once again. I am not sure what I could possibly have undertaken without the entire techniques provided by you regarding my field. It absolutely was a very traumatic situation for me personally, but seeing your expert tactic you solved it made me to weep with joy. I am grateful for this support and as well , have high hopes you find out what an amazing job you were doing instructing many people via a blog. Most probably you have never met all of us.

  • yeezy 2020年2月28日 下午6:18

    I just wanted to type a simple note in order to thank you for the fabulous tips you are showing here. My time intensive internet lookup has now been rewarded with reputable information to talk about with my best friends. I ‘d believe that we visitors are really blessed to exist in a superb place with so many outstanding people with insightful principles. I feel rather fortunate to have used your entire web page and look forward to tons of more entertaining moments reading here. Thanks again for everything.

  • nike lebron 15 2020年3月2日 上午7:14

    My wife and i were now joyous Chris managed to complete his studies from your precious recommendations he grabbed through the site. It is now and again perplexing to simply continually be handing out concepts which often many others may have been trying to sell. Therefore we realize we have the website owner to give thanks to because of that. All of the illustrations you’ve made, the straightforward blog menu, the relationships you will aid to promote – it’s got all impressive, and it is assisting our son and us know that the matter is fun, and that is exceedingly pressing. Thanks for all the pieces!

  • yeezy shoes 2020年3月5日 上午3:34

    I want to show my gratitude for your generosity in support of all those that should have assistance with your topic. Your very own dedication to passing the message all through was surprisingly powerful and has always encouraged most people much like me to achieve their ambitions. Your amazing interesting advice implies a great deal a person like me and far more to my office workers. Thanks a ton; from each one of us.

  • jordan retro 2020年3月7日 上午9:41

    I definitely wanted to send a small note in order to say thanks to you for those unique guides you are writing on this website. My time-consuming internet research has now been paid with wonderful knowledge to talk about with my family. I ‘d assume that many of us readers are definitely lucky to be in a useful website with many perfect people with insightful points. I feel pretty blessed to have discovered the webpages and look forward to so many more pleasurable moments reading here. Thanks a lot once again for a lot of things.

  • kobe sneakers 2020年3月10日 上午4:50

    A lot of thanks for your entire work on this web site. Debby enjoys setting aside time for research and it’s easy to understand why. A lot of people notice all about the powerful form you create practical techniques through the web blog and even boost contribution from visitors about this area then our favorite girl is certainly being taught a whole lot. Take advantage of the rest of the new year. You have been conducting a superb job.

  • supreme clothing 2020年3月13日 上午10:51

    Thanks a lot for providing individuals with an extraordinarily pleasant opportunity to read critical reviews from this website. It’s usually so amazing and also stuffed with a good time for me and my office friends to search your website not less than 3 times in 7 days to learn the newest stuff you have got. And definitely, I am always fascinated considering the breathtaking guidelines you serve. Certain 2 points in this posting are clearly the very best we have had.

  • adidas stan smith shoes 2020年3月16日 上午9:05

    I in addition to my guys were found to be going through the best strategies from the website and so suddenly I got an awful suspicion I had not thanked you for those strategies. These people ended up as a consequence stimulated to study them and have truly been making the most of these things. I appreciate you for really being quite helpful and then for using such outstanding themes most people are really desirous to understand about. Our honest apologies for not expressing appreciation to you earlier.

  • off white nike 2020年3月19日 上午4:47

    I in addition to my buddies were actually checking out the best secrets located on your website and so the sudden I had a horrible feeling I had not thanked the web blog owner for those tips. Most of the young boys were consequently excited to learn them and have now sincerely been loving them. I appreciate you for getting indeed accommodating and for settling on these kinds of beneficial ideas millions of individuals are really needing to know about. Our own sincere apologies for not saying thanks to sooner.

  • cheap jordans 2020年3月22日 上午2:39

    I would like to convey my love for your kindness giving support to men and women who really want assistance with this subject. Your very own dedication to passing the solution along has been extremely practical and have specifically helped those much like me to arrive at their goals. Your own interesting guide signifies a whole lot a person like me and somewhat more to my office colleagues. Thank you; from everyone of us.

  • nike vapormax 2020年3月24日 上午11:58

    I wish to express appreciation to the writer for bailing me out of this dilemma. Right after exploring through the world wide web and meeting recommendations which are not productive, I was thinking my entire life was well over. Living devoid of the answers to the problems you have resolved through this website is a critical case, as well as the ones which could have in a wrong way damaged my entire career if I had not discovered your blog post. Your primary expertise and kindness in taking care of the whole lot was crucial. I don’t know what I would’ve done if I had not discovered such a stuff like this. I am able to now look ahead to my future. Thanks very much for your skilled and amazing help. I won’t be reluctant to recommend your web page to any person who should have support on this problem.

  • Free Inpatient Drug Rehab Centers Near Me 2020年3月26日 下午12:48

    Substance Abuse Programs http://aaa-rehab.com Drug Rehab Centers http://aaa-rehab.com Substance Abuse Clinic
    http://aaa-rehab.com

  • michael kors 2020年3月27日 上午5:29

    I together with my friends were found to be digesting the excellent things from your site then quickly developed a horrible feeling I never thanked the website owner for those secrets. These young boys came very interested to read through them and have very much been making the most of these things. We appreciate you actually being very considerate and also for using these kinds of fantastic tips millions of individuals are really wanting to discover. My very own sincere apologies for not saying thanks to sooner.

  • jordan retro 2020年3月30日 下午2:03

    My spouse and i have been quite happy Ervin managed to carry out his research with the ideas he was given from your own web pages. It is now and again perplexing to just choose to be giving away secrets and techniques that most people have been selling. Therefore we see we need the website owner to give thanks to for this. All of the explanations you have made, the easy site navigation, the friendships your site aid to create – it’s got many incredible, and it’s really assisting our son and us know that the article is awesome, and that’s especially essential. Many thanks for all the pieces!

  • supreme clothing 2020年4月2日 下午12:32

    I intended to post you the tiny word in order to say thanks once again about the extraordinary suggestions you have shared here. It’s certainly incredibly open-handed with people like you to grant without restraint exactly what a number of people could have sold for an e-book to earn some profit on their own, notably seeing that you could have done it in case you desired. These strategies as well acted to become a fantastic way to comprehend someone else have a similar zeal like mine to grasp much more pertaining to this problem. I am sure there are many more pleasant instances in the future for individuals who view your blog post.

  • balenciaga 2020年4月9日 下午6:21

    I am only commenting to make you understand of the really good experience our daughter gained going through the blog. She discovered some things, most notably what it’s like to possess a very effective helping mood to let the rest effortlessly fully understand selected grueling topics. You undoubtedly surpassed my expectations. Many thanks for imparting these necessary, trusted, explanatory as well as easy guidance on your topic to Kate.

  • nike vapormax 2020年4月11日 下午10:51

    Thanks so much for providing individuals with an exceptionally breathtaking chance to read articles and blog posts from here. It is usually very beneficial plus full of a lot of fun for me and my office peers to visit the blog particularly thrice in one week to see the fresh tips you have got. Not to mention, we’re at all times astounded concerning the attractive inspiring ideas you give. Some two ideas in this posting are essentially the most effective we’ve ever had.

  • air jordan 2020年4月14日 上午2:50

    My husband and i were really satisfied when John managed to finish up his basic research because of the ideas he obtained when using the weblog. It is now and again perplexing to simply happen to be making a gift of techniques which usually some other people have been making money from. So we fully understand we have the blog owner to thank because of that. These illustrations you’ve made, the simple website navigation, the relationships you help promote – it’s all awesome, and it is helping our son in addition to our family imagine that that issue is fun, which is highly fundamental. Thanks for all!

  • nike huarache 2020年4月16日 上午5:51

    A lot of thanks for your own hard work on this site. My daughter really likes getting into investigations and it’s really easy to see why. A lot of people know all regarding the powerful medium you make reliable secrets by means of your blog and as well as recommend response from the others on this area of interest plus our favorite simple princess is without a doubt becoming educated a lot. Take pleasure in the rest of the year. You are always conducting a tremendous job.

  • jordans 2020年4月18日 上午5:09

    My husband and i have been absolutely thankful when Louis could do his homework out of the ideas he received using your weblog. It’s not at all simplistic just to find yourself making a gift of points which often many others have been trying to sell. So we remember we now have the website owner to thank for this. The specific illustrations you have made, the straightforward website navigation, the relationships you will aid to engender – it’s mostly fantastic, and it’s really assisting our son in addition to the family imagine that the concept is enjoyable, which is extraordinarily fundamental. Thanks for all!

  • golden goose sneakers 2020年4月20日 上午8:00

    My husband and i felt now more than happy Louis managed to finish off his inquiry with the ideas he received while using the web page. It’s not at all simplistic just to find yourself offering procedures that many other folks have been selling. And we also recognize we have got you to give thanks to for that. All the illustrations you have made, the simple web site navigation, the friendships you can aid to promote – it’s got mostly fabulous, and it is making our son in addition to the family understand the matter is interesting, which is quite serious. Thanks for the whole lot!

  • hermes birkin 2020年4月22日 上午9:35

    I wanted to develop a brief message so as to appreciate you for all of the marvelous facts you are sharing here. My time intensive internet research has now been recognized with good quality points to write about with my pals. I ‘d assume that most of us site visitors actually are unquestionably fortunate to live in a fantastic place with many brilliant professionals with useful points. I feel very much grateful to have encountered your website page and look forward to so many more thrilling times reading here. Thanks once more for all the details.

  • supreme 2020年4月24日 上午8:41

    I wish to express my affection for your generosity in support of persons who need help on this concern. Your personal commitment to passing the solution all-around turned out to be exceptionally helpful and has truly made regular people much like me to achieve their ambitions. Your amazing useful recommendations signifies this much to me and especially to my office colleagues. Best wishes; from each one of us.

  • GrodifsBridsFix 2020年4月25日 上午6:26

    free casino games online slots games free online gambling

  • golden goose sneakers 2020年4月26日 上午10:57

    I as well as my guys have already been looking at the best items on your site and so instantly I got a terrible suspicion I had not thanked the site owner for them. All of the young men ended up as a consequence thrilled to read all of them and have now in truth been making the most of these things. Thanks for truly being considerably accommodating and also for deciding upon these kinds of tremendous guides most people are really needing to be informed on. Our honest regret for not expressing appreciation to sooner.

  • hermes 2020年4月28日 上午10:12

    I must show some thanks to you just for rescuing me from this particular situation. Right after checking throughout the world-wide-web and finding recommendations that were not powerful, I assumed my life was over. Living without the strategies to the difficulties you’ve fixed as a result of your main short post is a crucial case, and those which could have badly affected my career if I had not noticed your web blog. That knowledge and kindness in maneuvering the whole lot was useful. I don’t know what I would have done if I hadn’t come across such a subject like this. I can also at this point relish my future. Thanks very much for the specialized and sensible guide. I will not be reluctant to endorse the blog to any person who would like counselling about this subject matter.

  • supreme clothing 2020年4月30日 上午8:18

    I simply had to thank you very much all over again. I do not know the things I would have created without those concepts revealed by you regarding such a situation. It had become a very fearsome matter for me personally, however , noticing a new professional manner you treated the issue forced me to weep for fulfillment. I am just happier for the advice and as well , pray you recognize what an amazing job you are carrying out educating many people all through a blog. I am certain you have never met all of us.

  • nalheerly 2020年5月1日 下午7:11

    slots games http://playcasinosw.com/ – casino play casino online casino play

  • lebron james shoes 2020年5月3日 上午7:53

    I actually wanted to type a quick remark to express gratitude to you for some of the awesome pointers you are giving out at this site. My time-consuming internet research has at the end been rewarded with really good facts and techniques to write about with my friends. I would assert that most of us readers actually are undeniably blessed to live in a really good website with very many special professionals with valuable tactics. I feel very much privileged to have encountered your webpages and look forward to some more entertaining times reading here. Thank you again for all the details.

  • GrodifsBridsFix 2020年5月5日 上午5:41

    casino real money http://casinogamespqr.com/ – vegas slots online free slots vegas slots online

  • nike shoes 2020年5月6日 上午7:26

    Needed to put you that tiny note just to thank you so much again for your personal unique strategies you’ve documented above. It was certainly pretty generous of people like you to allow unhampered what exactly many individuals could possibly have supplied as an e book in order to make some cash on their own, particularly considering the fact that you could possibly have tried it if you decided. The thoughts also served as the great way to be sure that other people online have a similar dream really like my own to learn lots more regarding this problem. I believe there are millions of more enjoyable situations in the future for folks who looked over your blog.

  • yeezy boost 350 2020年5月8日 下午3:56

    I and my guys ended up checking the excellent helpful tips from your web page and then instantly got a terrible suspicion I had not thanked the blog owner for those techniques. All the men are already absolutely stimulated to learn all of them and now have in actuality been taking advantage of these things. Many thanks for being really kind and then for getting these kinds of decent guides most people are really eager to understand about. My very own sincere regret for not expressing appreciation to you sooner.

  • GrodifsBridsFix 2020年5月9日 下午12:51

    online slot games slots games no deposit casino

  • bape hoodie 2020年5月15日 上午2:17

    Thank you a lot for providing individuals with remarkably terrific opportunity to read critical reviews from this website. It is always very amazing and as well , full of a lot of fun for me personally and my office acquaintances to search your site the equivalent of 3 times in a week to learn the new items you have. Not to mention, I’m also at all times pleased for the attractive things you give. Certain two facts in this post are surely the very best we have all ever had.

  • nalheerly 2020年5月20日 下午5:05

    hemp cbd cbd tinctures pure cbd oil

  • air max 270 2020年5月21日 上午5:32

    I needed to draft you the tiny word so as to thank you so much the moment again for your superb techniques you have shared at this time. It has been so shockingly generous with people like you to make unhampered precisely what many of us would have marketed for an e book in order to make some money for themselves, especially now that you could have tried it if you wanted. The strategies additionally acted to provide a good way to be sure that other individuals have a similar dreams just like mine to understand a great deal more related to this condition. I am certain there are some more fun opportunities in the future for people who check out your website.

  • curry 5 shoes 2020年5月23日 下午2:54

    Thanks so much for providing individuals with such a pleasant chance to read articles and blog posts from this site. It’s always very cool and packed with a lot of fun for me personally and my office colleagues to search your site more than 3 times a week to read the newest stuff you have got. And lastly, I’m also always astounded with the staggering knowledge you give. Selected 3 areas in this article are undeniably the simplest we have ever had.

  • birkin bag 2020年5月26日 上午6:15

    My husband and i felt quite thrilled Albert could deal with his analysis through your ideas he made through your blog. It is now and again perplexing to just find yourself giving freely techniques some other people may have been selling. We really fully grasp we’ve got the writer to give thanks to because of that. The specific explanations you have made, the easy site menu, the friendships you give support to foster – it is mostly incredible, and it is helping our son in addition to our family believe that that idea is enjoyable, and that is especially fundamental. Many thanks for all the pieces!

  • adidas nmd r1 2020年5月28日 下午2:52

    Thanks a lot for giving everyone remarkably wonderful possiblity to discover important secrets from this site. It is usually so enjoyable and packed with a lot of fun for me and my office colleagues to visit your blog a minimum of thrice every week to study the fresh stuff you have got. And definitely, I’m so actually satisfied for the staggering knowledge you serve. Selected 4 facts in this article are certainly the best we’ve had.

  • coach purse 2020年5月31日 上午5:11

    I precisely wanted to say thanks all over again. I am not sure the things I would’ve sorted out without these smart ideas contributed by you over my topic. It actually was the frustrating situation in my opinion, nevertheless looking at the specialized strategy you resolved the issue forced me to cry with delight. I am happier for the guidance and thus expect you recognize what a great job you are always carrying out educating other individuals through your web page. Probably you’ve never got to know any of us.

  • michael kors outlet 2020年6月2日 上午11:53

    Needed to put you that very small remark in order to say thank you again for all the spectacular strategies you have documented on this website. This is really strangely open-handed of people like you to give easily what exactly a number of us could have marketed for an e book to earn some dough for themselves, even more so considering that you might have done it if you desired. Those points in addition served like a good way to be aware that other people have a similar dreams the same as my personal own to understand a great deal more when it comes to this condition. I’m certain there are a lot more enjoyable moments ahead for folks who start reading your website.

联系我们

15555333984

在线咨询:点击这里给我发消息

邮件:lxa6@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code