Jump to content

Need Help Finding Label Element


shlumph

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/222300-need-help-finding-label-element/
Share on other sites

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.