php - Extracting text after before and after a | using preg_replace -


in efforts build stackoverflows linking system trying this;

$raw = '[[path.html|link description]]';  $str = preg_replace('#\[(\?)|(\?)]#', '<a href="$1">$2</a>', $raw);  echo $str; //$str should not <a href="path.html">link description</a> 

this should have worked, keep getting same text output. idea put part before | href , 1 after | link description. in end, have fail.

i took woking example, i'm stuck after adding | part.

the problem on regex hadn't escaped | having or expression.

you can use regex:

\[\[(.*?)\|(.*?)\]\] 

working demo

enter image description here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -