1

I have those two lines of code written in python i want to convert them to php, please help i don't know how to do this in php.

#code in python:
vowels= re.compile(ur'[\u064B-\u0652]')
newstr = vowels.sub('', str)

thank you

3 Answers 3

2

I think this is equivalent:

<?php
    $vowels ='/[\x{064B}-\x{0652}]/u'; 
    $newstr = preg_replace($vowels,"",$str);

The string should be UTF-8 encoded.

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

1 Comment

it works thank you very much, i've made it using another way but your way is the best,
2

I believe what you want is PHP's preg_replace(). I have no idea how PHP handles Unicode so I'm unsure if you can just take the Python pattern as-is and use it with PHP, but the syntax for using preg_replace() would be something like this:

<?php
$mystring = "jask;lfjalksdf"
$pattern = "/\u064B-\u0652/";
$replacement = "";

echo preg_replace($pattern, $replacement, $mystring);
?>

1 Comment

Thank you for your reply, i still have that problem with Unicode, the regex expresion is not correct. I get this error: Warning: preg_replace() [function.preg-replace]: Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset 1
1

re.compile() means its compiling a regular expression. Look at this for some help.

The sub function is essentially adding str to the beginning of the regular expression.

More info on python regular expressions can be found here

1 Comment

Thank you for the links, but my real problem is with the unicode in php i don't knwo how to do the same thinkg in php.

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.