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);
Related
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
I want to make search box with ability to search for word variations using the asterisk (*).
An asterisk (*) replaces one letter, can be used more than once in a word.
For example, searching on the term wom*n will locate records containing both woman and women and so on...
Any tips to achieve this in PHP ?
Assuming you wil do this with a database.
// The var we will use: $_POST['var']
$query = "SELECT FROM yourTable WHERE name LIKE ".translateVar($_POST['var']);
function translateVar($n){
return str_replace("*", "_", $n);
}
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
How do I remove characters till there comes another character in a string?
For example:
String is this: 0030051
Now I want to remove ALL 0's before another character (like: 1) comes.
So the string will become this: 30051.
Is there a PHP function for this or is this easier with Javascript/jQuery ? (I'd prefer PHP)
cast it to integer
$var = (int)$var;
Source - Reference
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
i want to check following by function preg_match:
1)Arabic letters
2)English letters
3)numbers
4)spaces, dashes ( - ) and single quotes ( ' )
i use php language
i tried
preg_match("~^[a-z\-'\s]{1,60}$~i", $nam)
You can use this character class : \p{Arabic}
Example:
preg_match("~^[a-z\-'\s\p{Arabic}]{1,60}$~iu", $nam)
strings are treated as utf8 with the \u modifier
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.
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/+]/