rspec/rules/S5856/php/rule.adoc
Karim El Ouerghemmi 0cb71fb085
Modify rule S5856: Add PHP as covered language (#338)
* Modify rule S5856: Add PHP as covered language

* Fix code example
2021-09-14 13:32:14 +00:00

23 lines
506 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

include::../description.adoc[]
To match a literal string, rather than a regular expression, either all special characters should be escaped or methods that dont use regular expressions should be used.
== Noncompliant Code Example
----
preg_match("/([/", $input);
preg_replace("/[/", "{", $input);
preg_replace("/(\\w+-(\\d+)/", "1234", $input);
----
== Compliant Solution
----
preg_match("/\\(\\[/", $input);
str_replace("([", "{", $input);
preg_replace("/(\\w+)-(\\d+)/", "1234", $input);
----