2

I have a text like "MASTER_LECTURE.NAME" so want to replace *MASTER_LECTURE* with space or another string. how to do that on regex php?

*i'm very newbie for REGEX. thanks

2 Answers 2

1

You can do this with regular expression or simple string function

$string = 'MASTER_LECTURE.NAME';

$string_replace = 'MASTER_LECTURE';

// Regular expression
preg_replace('/'.preg_quote($string_replace).'/is', '', $string);

// String function
$string = str_replace($string_replace, '', $string);

http://php.net/manual/en/function.preg-replace.php

http://php.net/manual/en/function.str-replace.php

Sign up to request clarification or add additional context in comments.

1 Comment

nice @delphist. Can you show me the pattern when word MASTER_LECTURE will dynamic depend on string that we submit?
1

if you are only replacing a string and not a pattern you can use str_replace

2 Comments

you do not need a formula. Its just str_replace($search,$replace, $subject). if its really a word and not a patter you should use this since its lighter
i need the pattern because the words will by dinamic.

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.