0

I have a foreach array which contains several text strings.

foreach ($this->arrCustomFields as $field) {
    echo ($field['lbl']->Name);
}

Following are the strings in above array.

abcdefg 
mention 
plcplc 
xxxx_Models

I want to match shell style wildcard + text "*Models" and replace it with "mymodels" and commit the changes in the same foreach array.

1 Answer 1

1

PHP supports Regular Expressions. You can use those with preg_replace to do the replacement:

$field['lbl']->Name = preg_replace("/.*Models/", "mymodels", $field['lbl']->Name);
Sign up to request clarification or add additional context in comments.

3 Comments

Glad I could help ;) If this is not exactly what you're trying to replace (actually *can work different in different environments, it can match "as much as possible" (greedy) or "as little as necessary" (non-greedy), and one can search case-sensitive or -insensitive), tell us more about what should and should not match, and the regular expression used can be fitted to your needs.
by the way how can I contact you, do you do paid work?
@user2107349 Send me a mail to < johannes+stackoverflow[at]schweinlein.de >. No promises though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.