Home Backend Development PHP Tutorial PHP regular expression efficiency greedy, non-greedy and backtracking analysis (recommended)

PHP regular expression efficiency greedy, non-greedy and backtracking analysis (recommended)

Jan 09, 2017 am 10:16 AM

Let’s first understand what is greedy in regular expressions and what is non-greedy? Or what is matching priority quantifier and what is ignoring priority quantifier?

Okay, I don’t know what the concept is, let’s give an example.

A student wanted to filter the content between them. This is how he wrote the regular rules and procedures.

1

$str = preg_replace(&#39;%<script>.+?</script>%i&#39;,&#39;&#39;,$str);//非贪婪

Copy after login

It seems like there is nothing wrong with it, but in fact it is not. If

1

$str = &#39;<script<script>alert(document.cookie)</script>>alert(document.cookie)</script>&#39;;

Copy after login

then after the above program processing, the result is

1

2

3

4

$str = &#39;<script<script>alert(document.cookie)</script>>alert(document.cookie)</script>&#39;;

$str = preg_replace(&#39;%<script>.+?</script>%i&#39;,&#39;&#39;,$str);//非贪婪

print_r($str);

//$str 输出为 <script>alert(document.cookie)</script>

Copy after login

Still He couldn't achieve the effect he wanted. The above is non-greed, and some are called laziness. The sign of non-greedy is to add ? after the quantitative metacharacter, such as +?, *?, ?? (more special, I will write about it in the future BLOG), etc. That is, it means non-greedy. If you don’t write ?, it means greedy. For example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

$str = &#39;<script<script>alert(document.cookie)</script>>alert(document.cookie)</script>&#39;;

$str = preg_replace('%<script>.+</script>%i','',$str);//非贪婪

print_r($str);

//$str 输出为 <script 只有这些了,好像还是不太合适,哈,您知道如何重写那个正则吗?<="" pre=""><div class="contentsignin">Copy after login</div></div><p> </p><p></p><p> The above is an introduction to the difference between greedy and non-greedy. Next, let’s talk about backtracking problems caused by greed and non-greed. Let’s look at a small example first. </p><p>The regular expression is \w*(\d+), and the string is cfc456n. Then, what is the $1 matched by this regular expression? ? </p><p>If your answer is 456, then congratulations, your answer is wrong. The result is not 456, but 6. Do you know why? </p><p>CFC4N will explain that when the regular engine uses regular \w*(\d+) to match the string cfc456n, it will first use \w* to match the string cfc456n. First, \w* will match the character All the characters in the string cfc456n are then handed over to \d+ to match the remaining string, and the rest is gone. At this time, the \w* rule will reluctantly spit out a character for \d+ to match. At the same time, Before spitting out characters, record a point. This point is the point used for backtracking. Then \d+ matches n. If it is found that the match cannot be successful, \w* will be asked to spit out another character again. \w* will record it again first. A point to backtrack and spit out one more character. At this time, the matching result of \w* is only cfc45, and 6n has been spit out. \d+ matches 6 again. If it is found that the match is successful, the engine will be notified that the match is successful, and it will be displayed directly. Therefore, the result of (\d+) is 6, not 456. </p><p>When the above regular expression is changed to \w*?(\d+) (note that this is non-greedy), the string is still cfc456n. So, at this time, what is the $1 of the regular match? ? </p><p>Student A answered: The result is 456. </p><p>Well, yes, correct, it is 456. CFC4N would like to ask, why is it 456? </p><p>Let me explain why it is 456</p><p>There is a rule in regular expressions that quantifiers are matched first, so \w*? will match the string cfc456 first, because \w*? Whether greedy or not, the regular engine will use the expression \w+? to only match one string at a time, and then transfer control to the following \d+ to match the next character. At the same time, it will record a point for unsuccessful matching. At this time, return here and match again, which is the backtracking point. Since \w is followed by the quantifier *, * represents 0 to countless times, so the first is 0 times, that is, \w*? matches an empty space, records the traceback point, and hands control to \d+,\d+ to match cfc456n The first character c of , then, the matching fails, so the control is handed over to \w*? to match the c of cfc456n, \w*? matches c successfully, because it is not greedy, so it only matches each time A character, record the traceback point, and then give control to \d+match f, then, \d+ match f and fail again, then give control to \w*?, \w*? then match c, record the traceback point ( At this time \w*? The matching result is cfc), and then give control to \d+, \d+ matches 4, and the match is successful. Then, since the quantifier is +, it is 1 to countless times, so it continues to match, Match 5 again, success, then match 6 again, success, then continue the matching operation, the next character is n, the match fails, at this time, \d+ will hand over the control. Since there is no regular expression after \d+, the entire regular expression is declared to be matched, and the result is cfc456, of which the first set of results is 456. Dear classmate, do you understand the result of the question just now, why is it 456? </p><p>Okay, have you understood the principles of greedy and non-greedy matching from the above example? Do you understand when you need to use greedy or non-greedy to process your string? <br/></p><p> Brother Bird’s article talks about expressions and programs as </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>$reg = "/<script>.*?<\/script>/is";

$str = "<script>********</script>"; //长度大于100014

$ret = preg_repalce($reg, "", $str); //返回NULL</pre><div class="contentsignin">Copy after login</div></div><p> </p><p></p><p>The reason is that there are too many backtrackings until Causes exhaustion of stack space and stack explosion. </p><p>Let’s look at another example. </p><p>String</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>$str = &#39;<script>123456</script>&#39;;</pre><div class="contentsignin">Copy after login</div></div><p> </p><p></p><p>The regular expression is </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>$strRegex1 = &#39;%<script>.+<\/script>%&#39;;

$strRegex2 = &#39;%<script>.+?<\/script>%&#39;;

$strRegex3 = &#39;%<script>(?:(?!<\/script>).)+<\/script>%&#39;;</pre><div class="contentsignin">Copy after login</div></div><p> </p>

<p></p>

<p> The above is the greedy, non-greedy and backtracking analysis of PHP regular expression efficiency introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website! </p>

<p>For more PHP regular expression efficiency, greedy, non-greedy and backtracking analysis (recommended) related articles, please pay attention to the PHP Chinese website! </p>

<p><br></p>

 

 

                        </div>

                    </div>

                    <div class="wzconShengming_sp">

                        <div class="bzsmdiv_sp">Statement of this Website</div>

                        <div>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</div>

                    </div>

                </div>

 

                <ins class="adsbygoogle"

     style="display:block"

     data-ad-format="autorelaxed"

     data-ad-client="ca-pub-5902227090019525"

     data-ad-slot="2507867629"></ins>

<script>

     (adsbygoogle = window.adsbygoogle || []).push({});

</script>

 

 

                <div class="AI_ToolDetails_main4sR">

 

 

                <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5902227090019525" data-ad-slot="3653428331" data-ad-format="auto" data-full-width-responsive="true"></ins>

    <script>

        (adsbygoogle = window.adsbygoogle || []).push({});

    </script>

 

 

                    <!-- <div class="phpgenera_Details_mainR4">

                        <div class="phpmain1_4R_readrank">

                            <div class="phpmain1_4R_readrank_top">

                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"

                                    onerror="this.onerror=''; this.src='/static/imghw/default1.png'"

                                    src="/static/imghw/hotarticle2.png" alt="" />

                                <h2>Hot Article</h2>

                            </div>

                            <div class="phpgenera_Details_mainR4_bottom">

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796793874.html" title="How to fix KB5055523 fails to install in Windows 11?" class="phpgenera_Details_mainR4_bottom_title">How to fix KB5055523 fails to install in Windows 11?</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>3 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796793871.html" title="How to fix KB5055518 fails to install in Windows 10?" class="phpgenera_Details_mainR4_bottom_title">How to fix KB5055518 fails to install in Windows 10?</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>3 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796791957.html" title="Roblox: Dead Rails - How To Tame Wolves" class="phpgenera_Details_mainR4_bottom_title">Roblox: Dead Rails - How To Tame Wolves</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>4 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796792155.html" title="Strength Levels for Every Enemy & Monster in R.E.P.O." class="phpgenera_Details_mainR4_bottom_title">Strength Levels for Every Enemy & Monster in R.E.P.O.</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>4 weeks ago</span>

                                        <span>By 尊渡假赌尊渡假赌尊渡假赌</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796797907.html" title="Roblox: Grow A Garden - Complete Mutation Guide" class="phpgenera_Details_mainR4_bottom_title">Roblox: Grow A Garden - Complete Mutation Guide</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>2 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                        </div>

                            <div class="phpgenera_Details_mainR3_more">

                                <a href="https://www.php.cn/article.html">Show More</a>

                            </div>

                        </div>

                    </div> -->

 

 

                                            <div class="phpgenera_Details_mainR3">

                            <div class="phpmain1_4R_readrank">

                                <div class="phpmain1_4R_readrank_top">

                                    <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" alt="">

                                    <h2>Hot AI Tools</h2>

                                </div>

                                <div class="phpgenera_Details_mainR3_bottom">

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title">

                                                    <h3>Undresser.AI Undress</h3>

                                                </a>

                                                <p>AI-powered app for creating realistic nude photos</p>

                                            </div>

                                        </div>

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title">

                                                    <h3>AI Clothes Remover</h3>

                                                </a>

                                                <p>Online AI tool for removing clothes from photos.</p>

                                            </div>

                                        </div>

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title">

                                                    <h3>Undress AI Tool</h3>

                                                </a>

                                                <p>Undress images for free</p>

                                            </div>

                                        </div>

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title">

                                                    <h3>Clothoff.io</h3>

                                                </a>

                                                <p>AI clothes remover</p>

                                            </div>

                                        </div>

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title">

                                                    <h3>Video Face Swap</h3>

                                                </a>

                                                <p>Swap faces in any video effortlessly with our completely free AI face swap tool!</p>

                                            </div>

                                        </div>

                                                                </div>

                                <div class="phpgenera_Details_mainR3_more">

                                    <a href="https://www.php.cn/ai">Show More</a>

                                </div>

                            </div>

                        </div>

                     

 

                    <script src="https://sw.php.cn/hezuo/cac1399ab368127f9b113b14eb3316d0.js" type="text/javascript"></script>

 

                    <div class="phpgenera_Details_mainR4">

                        <div class="phpmain1_4R_readrank">

                            <div class="phpmain1_4R_readrank_top">

                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" alt="">

                                <h2>Hot Article</h2>

                            </div>

                            <div class="phpgenera_Details_mainR4_bottom">

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796793874.html" title="How to fix KB5055523 fails to install in Windows 11?" class="phpgenera_Details_mainR4_bottom_title">How to fix KB5055523 fails to install in Windows 11?</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>3 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796793871.html" title="How to fix KB5055518 fails to install in Windows 10?" class="phpgenera_Details_mainR4_bottom_title">How to fix KB5055518 fails to install in Windows 10?</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>3 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796791957.html" title="Roblox: Dead Rails - How To Tame Wolves" class="phpgenera_Details_mainR4_bottom_title">Roblox: Dead Rails - How To Tame Wolves</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>4 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796792155.html" title="Strength Levels for Every Enemy & Monster in R.E.P.O." class="phpgenera_Details_mainR4_bottom_title">Strength Levels for Every Enemy & Monster in R.E.P.O.</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>4 weeks ago</span>

                                        <span>By 尊渡假赌尊渡假赌尊渡假赌</span>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/1796797907.html" title="Roblox: Grow A Garden - Complete Mutation Guide" class="phpgenera_Details_mainR4_bottom_title">Roblox: Grow A Garden - Complete Mutation Guide</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <span>2 weeks ago</span>

                                        <span>By DDD</span>

                                    </div>

                                </div>

                                                        </div>

                            <div class="phpgenera_Details_mainR3_more">

                                <a href="https://www.php.cn/article.html">Show More</a>

                            </div>

                        </div>

                    </div>

 

 

                                            <div class="phpgenera_Details_mainR3">

                            <div class="phpmain1_4R_readrank">

                                <div class="phpmain1_4R_readrank_top">

                                    <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" alt="">

                                    <h2>Hot Tools</h2>

                                </div>

                                <div class="phpgenera_Details_mainR3_bottom">

                                                                        <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/toolset/development-tools/92" title="Notepad++7.3.1" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Notepad++7.3.1">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/toolset/development-tools/92" title="Notepad++7.3.1" class="phpmain_tab2_mids_title">

                                                    <h3>Notepad++7.3.1</h3>

                                                </a>

                                                <p>Easy-to-use and free code editor</p>

                                            </div>

                                        </div>

                                                                            <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Chinese version">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" class="phpmain_tab2_mids_title">

                                                    <h3>SublimeText3 Chinese version</h3>

                                                </a>

                                                <p>Chinese version, very easy to use</p>

                                            </div>

                                        </div>

                                                                            <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/toolset/development-tools/121" title="Zend Studio 13.0.1" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Zend Studio 13.0.1">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/toolset/development-tools/121" title="Zend Studio 13.0.1" class="phpmain_tab2_mids_title">

                                                    <h3>Zend Studio 13.0.1</h3>

                                                </a>

                                                <p>Powerful PHP integrated development environment</p>

                                            </div>

                                        </div>

                                                                            <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title">

                                                    <h3>Dreamweaver CS6</h3>

                                                </a>

                                                <p>Visual web development tools</p>

                                            </div>

                                        </div>

                                                                            <div class="phpmain_tab2_mids_top">

                                            <a href="https://www.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" class="phpmain_tab2_mids_top_img">

                                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac version">

                                            </a>

                                            <div class="phpmain_tab2_mids_info">

                                                <a href="https://www.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" class="phpmain_tab2_mids_title">

                                                    <h3>SublimeText3 Mac version</h3>

                                                </a>

                                                <p>God-level code editing software (SublimeText3)</p>

                                            </div>

                                        </div>

                                                                    </div>

                                <div class="phpgenera_Details_mainR3_more">

                                    <a href="https://www.php.cn/ai">Show More</a>

                                </div>

                            </div>

                        </div>

                                         

 

                     

                    <div class="phpgenera_Details_mainR4">

                        <div class="phpmain1_4R_readrank">

                            <div class="phpmain1_4R_readrank_top">

                                <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" alt="">

                                <h2>Hot Topics</h2>

                            </div>

                            <div class="phpgenera_Details_mainR4_bottom">

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/java-tutorial" title="Java Tutorial" class="phpgenera_Details_mainR4_bottom_title">Java Tutorial</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/eyess.png" alt="">

                                            <span>1661</span>

                                        </div>

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/tiezi.png" alt="">

                                            <span>14</span>

                                        </div>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/cakephp-tutor" title="CakePHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">CakePHP Tutorial</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/eyess.png" alt="">

                                            <span>1417</span>

                                        </div>

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/tiezi.png" alt="">

                                            <span>52</span>

                                        </div>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/laravel-tutori" title="Laravel Tutorial" class="phpgenera_Details_mainR4_bottom_title">Laravel Tutorial</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/eyess.png" alt="">

                                            <span>1311</span>

                                        </div>

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/tiezi.png" alt="">

                                            <span>25</span>

                                        </div>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/php-tutorial" title="PHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">PHP Tutorial</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/eyess.png" alt="">

                                            <span>1261</span>

                                        </div>

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/tiezi.png" alt="">

                                            <span>29</span>

                                        </div>

                                    </div>

                                </div>

                                                            <div class="phpgenera_Details_mainR4_bottoms">

                                    <a href="https://www.php.cn/faq/c-tutorial" title="C# Tutorial" class="phpgenera_Details_mainR4_bottom_title">C# Tutorial</a>

                                    <div class="phpgenera_Details_mainR4_bottoms_info">

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/eyess.png" alt="">

                                            <span>1234</span>

                                        </div>

                                        <div class="phpgenera_Details_mainR4_bottoms_infos">

                                            <img src="/static/imghw/tiezi.png" alt="">

                                            <span>24</span>

                                        </div>

                                    </div>

                                </div>

                                                        </div>

                            <div class="phpgenera_Details_mainR3_more">

                                <a href="https://www.php.cn/faq/zt">Show More</a>

                            </div>

                        </div>

                    </div>

                </div>

            

Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

See all articles