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.