Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I convert

ereg_replace(".*.(.*)$","\1",$imgfile);

to

preg_replace... ?

?

I'm having trouble with it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
475 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should know 4 main things to port ereg patterns to preg:

  1. Add delimiters(/): 'pattern' => '/pattern/'

  2. Escape delimiter if it is a part of the pattern: 'patt/ern' => '/patt/ern/'
    Achieve it programmatically in following way:
    $ereg_pattern = '<div>.+</div>';
    $preg_pattern = '/' .addcslashes($ereg_pattern, '/') . '/';

  3. eregi(case-insensitive matching): 'pattern' => '/pattern/i' So, if you are using eregi function for case insenstive matching, just add 'i' in the end of new pattern('/pattern/').

  4. ASCII values: In ereg, if you use number in the pattern, it is assumed that you are referring to the ASCII of a character. But in preg, number is not treated as ASCII value. So, if your pattern contain ASCII value in the ereg expression(for example: new line, tabs etc) then convert it to hexadecimal and prefix it with x.
    Example: 9(tab) becomes x9 or alternatively use .

Hope this will help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...