# PHP: need help with preg\_replace

**URL:** <https://forum.kirupa.com/t/php-need-help-with-preg-replace/246866>\
**Category:** programming\
**Created:** [December 15, 2007, 5:10pm UTC](https://forum.kirupa.com/t/php-need-help-with-preg-replace/246866 "2007-12-15T17:10:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![silverType](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@silverType](https://forum.kirupa.com/u/silverType)\
**Post date:** [December 15, 2007, 5:10pm UTC](https://forum.kirupa.com/t/php-need-help-with-preg-replace/246866/1 "2007-12-15T17:10:28Z")

</div>

Hi,  
I want to remove the onclick event from my html tag. For instance, given the following:

\<input type=“text” name=“txtEmail” id=“txtEmail” onclick=“parent.showTestStrategyDiv(this.id, this.name);” /\>

‘onclick’ will be removed and the new string will look like this:

\<input type=“text” name=“txtEmail” id=“txtEmail” /\>

To do this, I call the preg\_replace method in php:

$alteredContent3 = preg\_replace("#(\<input.+?)(on[Cc]lick.+?)(/?\>)#i", “\1\3”, $alterContent2);

Given that alterContent2 is the the html page which I want to alter. Somehow, when I tried to print out the values for $alteredContent3, nothing is returned. Any help is greatly appreciated. Thanks in advance.
