PHP Regular Expression difference [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can someone explain the difference between these two lines of code?
preg_replace("/[^0-9]/", '', $Phone);
preg_replace('/[^0-9\/+]/', '', $Phone);
Ive been hunting online and cant seem to find anything explaining the extra "/+"

The following matches anything that's not a digit.
/[^0-9]/
The following matches anything that's not a digit, /, or +:
/[^0-9/+]/

Related

Remove string after dash IF end string matches given string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
What I'm trying to do is remove a string after the dash if the string after the dash matches what is appended.
For example it'd be like: if endofstring is equal to givenstring, remove dash and everything after, else keep the dash
Thanks for any help!
$string='Hello this is the-end';
$remove='end';
$i=strrpos($string, $remove);
if ($i===strlen($string)-strlen($remove)) $string=substr($string, 0, $i-1);
var_dump($string);

PHP Only allow certain characters and replace all others [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a PHP Variable which i need to remove all special characters from, like % / é / ! etc
how can i replace all characters OTHER than A-Z / a-z / 0-9 and . (full stop) with a _
Something like this ought to work.
preg_replace("/[^A-Za-z0-9\.]/", "_", $str);

Regex to select everything in between two characters [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create a regex that will select the data between two characters (& - #).
& foo #
I would like to select foo.
Any ideas? Good explanations are also appreciated.
how about this:
preg_match('~&([^#]*)#~',$content,$match);

How to use regex to get the numbers out of this type? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want a regex that will help me to get the 4 numbers before the cc.
The RegEx must contain the cc to identify these exact number.
Example:
1600cc
You should use:
/(\d{4})cc\b/
\b ensures that "cc" is at the and of the word.
preg_match('/(\d{4})cc/', $string, $match);
$match[1] will contain the number.

php filter with get variables [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I suck at regexp but i'd like to just do a simple filter where / is replaced with 1, " is replaced with 2 and < is replaced with 3.
I'd appreciate an example where the syntax would be straight forward, i'd like to run this filter through the input of a get variable provided by the user. A syntax like:
replace(/,1)
replace(",2)
replace(<,3)
.
Thanks.
I really don't see the need for regex here.. You can just use str_replace
E.g.
str_replace('/', '1', $_GET['var']);

Categories