Ordered string to array PHP

I have a problem with converting the string: $str = "1. List of word synonyms 2) Glass plastic products 3. Other product"; into an array list: Array([0] => List of word synonyms [1] => Glass plastic products [2] => Other product) I tried using preg_replace, but I can’t come up with a pattern that would… Read More Ordered string to array PHP

Preg Replace in sub string leaving a part of the string remaining

I am using preg_replace I am trying to replace everything between (and ideally including): [BW] and [/BW] with an empty string. $string = MyText-[BW]field[/BW]-[COUNTER]0001[/COUNTER]-[D]YY/MM/DD[/D][BW]field_2[/BW] $string = preg_replace(‘/’.preg_quote(‘[BW]’).'[\s\S]+?’.'[\/BW]’.’/’, ”, $string); However the output I am getting seems to be keeping the follwing part: BW] i.e. MyText-BW]-[COUNTER]0001[/COUNTER]-[D]YY/MM/DD[/D]BW] The result I want is MyText–[COUNTER]0001[/COUNTER]-[D]YY/MM/DD[/D] I have a workaround… Read More Preg Replace in sub string leaving a part of the string remaining

PHP preg_replace to extract first number before dash

Many examples are – but still a stumbling block in my mind. I need to extract first number 21538 from links like $input_line =’https://ex.com/prom-nt/21538-asus-screen17.html’ using PHP preg_replace like preg_replace(‘/(^\D+)(.*)-(.*)/’, ‘\2’, $input_line); I get output 21538-asus using PHP preg_replace like preg_replace(‘/(^\D+)(.*)[0-9]-(.*)/’, ‘\2’, $input_line);) I lose last digit (8) and get output 2153 not 21538 – so… Read More PHP preg_replace to extract first number before dash