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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.