PHP Regex Release Issue

I am trying to create a field for sorting book titles that separates the leading "A, An, The" and adds them to the decimal places and the space. Thus, the "Road" will become "Dear", "

It sounds simple, but there is something in the code below that makes IE (no other browsers) splash out a huge block of gibberish.

$node_field[0]['value'] = preg_replace( '/^(A|An|The|a|an|the) (.*)/', "$2\x00,$1", $node->title ); 
+4
source share
1 answer

You should use something more like

 $node_field[0]['value'] = preg_replace( '/^(A|An|The) (.*)/i', "$2, $1", $node->title ); 

If I understand correctly, that should change any "A ...", "An ..." or "The ..." to "..., A", "..., An" and "... , The "respectively.

i after the slash in the Regex pattern makes it case insensitive, which should catch all versions of A, An or The.

+4
source

Source: https://habr.com/ru/post/1347809/


All Articles