tht13
tht13

Reputation: 47

PHP wont recognise double line feed

I am running a RST to php conversion and am using preg_match.

this is the rst i am trying to identify:

An example of the **Horizon Mapping** dialog box is shown below. A 
summary of the main features is given below. 

.. figure:: horizon_mapping_dialog_horizons_tab.png 

   **Horizon Mapping** dialog box, *Horizons* tab 

Some of the input values to the **Horizon Mapping** job can be changed 
during a Workflow using the internal programming language, IPL. For 
details, refer to the *IPL User Guide*. 

and I am using this regex:

$match = preg_match("/.. figure:: (.*?)(\n{2}[ ]{3}.*\n)/s", $text, &$result);

however it is returning as false. here is a link of the expression working on regex http://regex101.com/r/oB3fW7.

Upvotes: 1

Views: 69

Answers (2)

zx81
zx81

Reputation: 41848

My instinct would be to do some troubleshooting around the s flag as well as the $result variable passed by reference. To achieve the same without any interference from dots and the return variable, can you please try this regex:

..[ ]figure::[ ]([^\r\n]*)(?:\n|\r\n){2}[ ]{3}[^\r\n]*\R

In code, please try exactly like this:

$regex = "~..[ ]figure::[ ]([^\r\n]*)(?:\n|\r\n){2}[ ]{3}[^\r\n]*\R~";
if(preg_match($regex,$text,$m)) echo "Success! </br>";

Finally:

If this does not working, you might have a weird Unicode line break that php is not catching. To debug, for each character of your string, iterate through all the string's characters

  1. Iterate: foreach(str_split($text) as $c) {
  2. Print the character: echo $c . " value = "
  3. Print the value from this function: . _uniord($c) . "<br />"; }

Upvotes: 0

Toto
Toto

Reputation: 91518

Are you sure that the line break is \n, is doubt, use \R:

$match = preg_match("/.. figure:: (.*?)(\R{2}[ ]{3}.*\R)/s", $text, &$result);

\R stands for either \n, \r and \r\n

Upvotes: 2

Related Questions