shlumph Posted December 21, 2010 Share Posted December 21, 2010 Hi, With a string that looks like this: $this->addElement( 'ValidationTextBox', 'first_name', array( 'label' => 'First Name', 'trim' => true, 'required' => true, 'invalidMessage' => 'This field is required.' ) ); I would like to replace 'label' => 'First Name', with 'label' => $this->getView()->translate('First Name'), I will be reading a folder of PHP files and reading the code as a string. But I need some help coming up with a regular expression. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/222300-need-help-finding-label-element/ Share on other sites More sharing options...
shlumph Posted December 21, 2010 Author Share Posted December 21, 2010 I have something like this that I think might work: <?php $string = " $this->addElement( 'ValidationTextBox', 'email', array( 'label' => 'Email Address', 'trim' => true, 'required' => true, 'regExp' => '^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.\_]+\.(com|org|net|mil|edu)', 'invalidMessage' => 'Valid Email Required.' ) );"; $pattern = array(); $pattern[] = '/\'label\' => /'; $pattern[] = '/\',/'; $replacement = array(); $replacement[] = '\'label\' => $this->getView()->translate('; $replacement[] = '\'),'; echo preg_replace($pattern, $replacement, $string); Quote Link to comment https://forums.phpfreaks.com/topic/222300-need-help-finding-label-element/#findComment-1149921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.