Sometimes we need to remove anchors from html while displaying html content. You can easily remove links or anchors from a html content using PHP preg_replace() function with regular expressions.
Also, read:
- Convert Associative Array into XML in PHP
- Convert XML into Associative Array in PHP
- Converting an Array to JSON in PHP
- Converting JSON to Array or Object in PHP
Here is the complete code to remove anchors tags from a string using PHP.
<?php
$str = 'PHPZAG PHP <a href="https://www.phpzag.com/" title="PHP">TUTORIALS</a> AND ARTICLES.';
echo preg_replace('#<a.*?>([^>]*)</a>#i', '$1', $str);
?>
You may also like:
- Working with php.ini file Configuration
- Control Statements in PHP
- Convert Associative Array into XML in PHP
- Convert XML into Associative Array in PHP
- Using Prepared Statement with PHP & MySQL
- How to Upload File in PHP
- Converting an Array to JSON in PHP
- Converting JSON to Array or Object in PHP
- Manipulating PHP arrays: push, pop, shift, unshift
- Remove Repeated Words From String in PHP
- Converting a PHP Array to a Query String
- 15+ regular expressions for PHP developers
- 10 Most Important Directory Functions in PHP
- 10 little known but useful PHP functions
- PHP Script to Download Large Files Reliably
great job buddy…