0

i have this string

$output=' i want to <a class="SForm" onclick="ShowFormComment()"><img src="http://vnexpress.net/Images/Y-kien-cua-ban.gif" border="0" style="cursor:pointer" alt="Ý kiến của bạn" /> kiss you so much';

and i want to get

' i want to kiss you so much'

so i tried

$output =preg_replace('/<a class="SForm" class=(.*?)\Ý kiến của bạn" />/', '', $output);

but it didnt work

Warning: preg_replace(): Unknown modifier '&' in /Users/datlap/Desktop/str.php on line 10

Any idea?

0

2 Answers 2

1

To make it work escape the / before &.

$output =preg_replace('/<a class="SForm" class=(.*?)\Ý kiến của bạn" \/>/', '', $output);
                                                                                       ^

You are using / as the regex delimiter and there is a unescaped / in the regex which is being treated as the end delimiter.

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

Comments

1

You don't need to use regular expressions for something like that...

A much simpler solution would be to use

$output = strip_tags(htmlspecialchars_decode($output));

https://www.php.net/manual/en/function.htmlspecialchars-decode.php

https://www.php.net/manual/en/function.strip-tags.php

1 Comment

Ginormous built-in function library to the rescue!

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.