$input_lines="any word here related to #English must #be replaced.";
$result = preg_replace("/(#\w+)/", "<a href='bla bla'>$1</a>", $input_lines);

DEMO

OUTPUT:

any word here related to <a href='bla bla'>#English</a> must <a href='bla bla'>#be</a> replaced.
Answer from Nambi on Stack Overflow
🌐
PHP
php.net › manual › en › function.preg-replace.php
PHP: preg_replace - Manual
preg_replace() returns an array if the subject parameter is an array, or a string otherwise. If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or null if an error occurred.
🌐
W3Schools
w3schools.com › php › func_regex_preg_replace.asp
PHP preg_replace() Function
❮ PHP RegExp Reference · Use ... » · The preg_replace() function returns a string or array of strings where all matches of a pattern or list of patterns found in the input are replaced with substrings....
🌐
Phpliveregex
phpliveregex.com
PHP Live Regex
Test PHP regular expressions live in your browser and generate sample code for preg_match, preg_match_all, preg_replace, preg_grep, and preg_split!
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals › regular expressions
Search and Replace Strings With Regular Expressions in PHP | Envato Tuts+
March 30, 2021 - We began by learning how to use preg_match() or preg_match_all() to get all the strings that match a specific pattern. After that, we learned how to use preg_replace() and preg_replace_callback() to replace the matched patterns with some other ...
🌐
Rexegg
rexegg.com › regex-php.php
PHP Regex Tutorial
In such cases, str_replace can be faster than the preg_replace regex function: $string=str_replace('10','20','$string'); The preg_replace function comes in when you need a regex pattern to match the string to be replaced, for instance if you only wanted to replace '10' when it stands alone ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-preg_replace-function
PHP | preg_replace() Function - GeeksforGeeks
July 11, 2025 - Program 1: The following program replaces string by using the regular expression parameter. ... <?php // PHP program to illustrate // preg_replace function $string = 'November 01, 2018'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1} 02, $3'; // print output of function echo preg_replace($pattern, $replacement, $string); ?>
Find elsewhere
🌐
Medium
captainnoob.medium.com › command-execution-preg-replace-php-function-exploit-62d6f746bda4
Command Execution - preg_replace() PHP Function Exploit | RCE
October 10, 2020 - After executing this , preg_replace() the search for `as` and replace with `As` . ... To exploit the code, all the attacker has to do is provide some PHP code to execute, generate a regular expression which replaces some or all of the string with the code, and set the `e` modifier on the regular expression/pattern
🌐
Smarty
smarty.net › docs › en › language.modifier.regex.replace.tpl
regex_replace | Smarty
A regular expression search and replace on a variable. Use the preg_replace() syntax from the PHP manual. Although Smarty supplies this regex convenience modifier, it is usually better to apply regular expressions in PHP, either via custom functions or modifiers.
🌐
W3Schools
w3schools.com › php › php_regex.asp
PHP Regular Expressions
flush() ob_clean() ob_end_clean() ob_end_flush() ob_flush() ob_get_clean() ob_get_contents() ob_get_flush() ob_get_length() ob_get_level() ob_gzhandler() ob_implicit_flush() ob_list_handlers() ob_start() output_add_rewrite_var() output_reset_rewrite_vars() PHP RegEx · preg_filter() preg_grep() preg_last_error() preg_match() preg_match_all() preg_replace preg_replace_callback preg_replace_callback_array preg_split preg_quote PHP SimpleXML ·
🌐
Medium
medium.com › @wearedopethemes › replacing-ereg-replace-with-preg-replace-in-php-for-regex-handling-e4cdf53450e2
Replacing ereg_replace() with preg_replace() in PHP for Regex Handling | by DopeThemes.com | Medium
September 3, 2024 - Case Sensitivity: Unlike ereg_replace(), which is case-insensitive by default, preg_replace() requires you to specify the i modifier for case-insensitive matches, giving you more control over your regex patterns. Compatibility: Since ereg_replace() has been deprecated and removed from PHP, continuing to use it in your code can prevent you from upgrading to newer versions of PHP, exposing your applications to security risks and missing out on performance improvements.
🌐
Reintech
reintech.io › blog › understanding-implementing-php-preg-replace-function
Understanding and Implementing PHP's `preg_replace()` Function
April 14, 2023 - Learn how to use PHP's preg_replace() function for string manipulation tasks, including working with regular expressions and callback functions.
🌐
AWS
aws.amazon.com › blogs › industries › building-observability-on-amazon-managed-grafana-for-5g-o-ran-sites-built-on-eks-anywhere
Building Observability on Amazon Managed Grafana for 5G O-RAN sites built on EKS-Anywhere | Amazon Web Services
January 25, 2024 - An important step in the push for an open, virtualized, and intelligent 5G has been the proliferation of Open Radio Access Network (O-RAN), which seeks to improve Radio Access Network (RAN) flexibility and deployment velocity, while simultaneously reducing the capital and operating costs through ...
🌐
NGINX
nginx.org › en › docs › beginners_guide.html
Beginner’s Guide
nginx can be used to route requests ... such as PHP. The most basic nginx configuration to work with a FastCGI server includes using the fastcgi_pass directive instead of the proxy_pass directive, and fastcgi_param directives to set parameters passed to a FastCGI server. Suppose the FastCGI server is accessible on localhost:9000. Taking the proxy configuration from the previous section as a basis, replace the proxy_pass ...
🌐
Nusphere
nusphere.com › kb › phpmanual › function.preg-replace.htm
PHP Manual: preg_replace
PhpED - PHP IDE integrated development environment for developing web sites using PHP, HTML, Perl, JScript and CSS that combines a comfortable editor, debugger, profiler with the MySQl, PostrgeSQL database support based on easy wizards and tutorials.Easy to use for debugging PHP scripts, publishing ...