php - regex to format operators in a expression -
i need operators (arithmetic, comparison, logical...) in string...
((value+10)*10)>=300 || (array[key]-20==0&&"foo==bar"!=="") ...and add single whitespace before , after them (if doesn't exists)...
((value + 10) * 10) >= 300 || (array[key] - 20 == 0 && "foo==bar" !== "") ...ignoring between quotes or single quotes.
aditional rules:
- add space before pre-in/decrement operators
- add space after post-in/decrement operators
sounds easy can't how using regex in php. if can help!
i'm trying $str = preg_replace('(?<=[\w\]\)\s\"\'])\!=(?=[\w\]\)\s\"\'])', ' != ', $str); every operator, don't think it's idea.
Comments
Post a Comment