Đây là hàm xóa toàn bộ file trong một folder. Ví dụ bạn có folder A và trong folder A bạn không biết số lượng hình ảnh là bao nhiêu thì có thể sử dụng hàm dưới đây để xóa. Show
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. function removeAllFile($dir){ if (is_dir($dir)) { $structure = glob(rtrim($dir, "/").'/*'); if (is_array($structure)) { foreach($structure as $file) { if (is_dir($file)) recursiveRemove($file); else if (is_file($file)) @unlink($file); } } } } Cách sử dụng: removeAllFile('./a'); // xóa hết hình trong folder a Điểm yếu của hàm này là nếu số lượng file quá lớn thì sẽ chạy không ổn định vì chương trình PHP sẽ bị tràn bộ nhớ, vì vậy bạn có thể kết hợp với script trên server để xóa. Tuy nhiên nếu bạn biết cách phân chia folder thì mình nghĩ hoàn toàn có thể sử dụng hàm này được. Ví dụ với mỗi bài viết thì bạn đặt hình trong một folder, sau đó nếu xóa bài viết thì xóa luôn hình trong folder đó. Bài viết này được đăng tại [free tuts .net] Hàm Nội dung chính
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. Cú phápCú pháp: Trong đó:
Ví dụCode $str = 'This is a <b> Example</b> <a href="#fragment">String</a> <p>this a other string</p>'; echo $str; echo strip_tags($str) . "<br />"; Kết quả This is a Example String this a other string This is a Example String this a other string Code $str = 'This is a <b> Example</b> <a href="#fragment">String</a> <p>this a other string</p>'; echo $str; echo strip_tags($str, '<a><p>'); Kết quả This is a Example String this a other string This is a Example String this a other string Tham khảo: php.net Bài viết này được đăng tại [free tuts .net] Cùng chuyên mục:❮ PHP String Reference Nội dung chính
ExampleStrip the string from HTML tags: <?php Try it Yourself » Definition and UsageThe strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter. Note: This function is binary-safe. SyntaxParameter Values
Technical Details
More ExamplesExampleStrip the string from HTML tags, but allow <b> tags to be used: <?php Try it Yourself » ❮ PHP String Reference I want to display the first 110 characters of a database entry. Pretty easy so far:
But the above entry has html code in it that's been entered by the client. So it displays:
Obviously no good. I just want to strip out all html code, so I need to remove everything between < and > from the db entry THEN display the first 100 chars. Any ideas anyone? j0k 22.3k28 gold badges77 silver badges86 bronze badges asked Feb 4, 2013 at 9:47 1 use
answered Feb 4, 2013 at 9:48 Yogesh SutharYogesh Suthar 30.2k18 gold badges70 silver badges98 bronze badges 4 Use PHP's strip_tags() function. For example:
answered Feb 4, 2013 at 9:48 EM-CreationsEM-Creations 4,0274 gold badges38 silver badges55 bronze badges 2 Remove all HTML tags from PHP string with content!Let say you have string contains anchor tag and you want to remove this tag with content then this method will helpful.
Output:
answered Sep 4, 2016 at 18:26 Muhammad ShahzadMuhammad Shahzad 8,79021 gold badges79 silver badges128 bronze badges 1 use this regex:
from your example should stay: answered Feb 4, 2013 at 9:50 Maxim ShoustinMaxim Shoustin 78.2k28 gold badges200 silver badges222 bronze badges 5 For my this is best solution.
answered Aug 7, 2019 at 8:08 David G.David G. 211 silver badge3 bronze badges Strip the string from HTML tags:
Strip the string from HTML tags, but allow tags to be used:
answered Apr 18, 2021 at 9:53 lookly Devlookly Dev 3073 silver badges4 bronze badges In laravel you can use following syntax
answered Dec 10, 2018 at 17:18
Or if you have a content coming from the database;
answered Sep 29, 2020 at 9:39
Try this Bhargav Rao 47k27 gold badges121 silver badges136 bronze badges answered Dec 5, 2020 at 12:28 Not the answer you're looking for? Browse other questions tagged php or ask your own question.How can we remove the HTML tags from the data in PHP?The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter. How can we remove the HTML tags from the data?The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text. Which function is used to remove all HTML tags from a string passed to A from?Which function is used to remove all HTML tags from a string passed to a form? Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags. How do I remove HTML tag from string in Wordpress?wp_strip_all_tags is a built in wordpress function. Which is used to strip out tags from the given strings. It is a modified function of PHP strip_tags function or an extended version. strip_tags function is used to remove HTML and PHP tags from strings. |