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
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
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);
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);
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
OK there is an input field for visitor to enter something in it (like nickname lets say). I wish for (upcoming $_POST) variable to have at least (at least) 4 characters before starts to trigger function.
Here is some cosmetic example..
$inputdata = escapeHTML($_REQUEST['data']);
if($inputdata...)
{
//execute $inputdata
}
Any cool trick? Thx!
if (strlen($inputdata) >= 4)
This should work then
Or
if (mb_strlen($inputdata) >= 4) for non-latin text
Resources:
http://www.php.net/manual/en/function.mb-strlen.php
http://php.net/manual/en/function.strlen.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
Given this code snippet:
$nodes[$record->nid]->group = $record->group;
I do not understand what the first part (to the left of the equals sign) means?
Thanks.
$nodes is an array, and $record->nid is an index in that array. For this code to be valid, $record->nid must be either a string or an integer.
Calling $nodes[$record->nid] will return an object, that you are then calling group on.
I do not understand what the first part (to the left of the equals sign) means?
Breaking $nodes[$record->nid]->group apart:
$nodes is an array of objects
$nodes[$record->nid] accesses the element with a key of $record->nid
$nodes[$record->nid]->group access the group property of the object ($nodes[$record->nid])
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']);