Error in while system loop count [help]

Source: Internet
Author: User
While control loop number error [help] code... the following code has some problems. I used $ I to control the number of outputs. but replace it with break for a long time. please help... thank you... PHPcode // replace keyword functionReplaceKey ($ newstext) {global $ empire, while control loop times error [help]
The code above... the code below is a bit problematic. I would like to use $ I to control the number of outputs. but replace it with break once;
I thought about it for a long time.
Please help... thank you...

PHP code
  // Replace the keyword function ReplaceKey ($ newstext) {global $ empire, $ dbtbpre, $ public_r; if (empty ($ newstext) {return $ newstext ;} $ SQL = $ empire-> query ("select keyname, keyurl from {$ dbtbpre} enewskey"); $ I = 0; while ($ r = $ empire-> fetch ($ SQL) {if ($ I <5) {$ newstext = empty ($ public_r [repkeynum])? Str_replace ($ r [keyname], ''. $ r [keyname]. '', $ newstext): preg_replace ('/'. $ r [keyname]. '/',''. $ r [keyname]. '', $ newstext, $ public_r [repkeynum]);} else break; $ I ++;} return $ newstext ;}


------ Solution --------------------
Are you sure the query result is greater than 5?
------ Solution --------------------
I personally think that your debugging has a problem and the result is not exactly replaced as you said.
The value of $ public_r [repkeynum] does not change during function running, so else branch will not be executed.
------ Solution --------------------
The code control process should be okay.


$ Newstext = empty ($ public_r [repkeynum])? Str_replace ($ r [keyname], ''. $ r [keyname]. '', $ newstext): preg_replace ('/'. $ r [keyname]. '/',''. $ r [keyname]. '', $ newstext, $ public_r [repkeynum]);


This part.

So it seems that you should change it to the string returned by $ newstext. = xxxx, which is your final purpose.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.