Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I tried to use php rtrim() function to retrive username in the email address, but I met the following problem:
Case 1:
$email = 'merkerxu37#stackoverflow.com';
echo rtrim($email, '#stackoverflow.com');
I got the output:
merkerxu37
Case 2:
$email = 'merkerxu37#37signals.com';
echo rtrim($email, '#37signals.com');
I got the output:
merkerxu
Can anybody tell me why the "37" is missing in Case 2?
That is because you have entered the second parameter '#37signals.com' which consider 3, 7 or 37 as characters to be trimmed.
Reference
trim (and its single-sided variants) take a list of characters to remove. Since 3 and 7 feature in the list you gave, it trimmed them.
Why not just do this?
echo explode("#",$email,2)[0];
// If you don't have PHP 5.4:
// $parts = explode("#",$email,2); echo $parts[0];
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need to get a substring (see examples, bold part) from the string. All strings begin with "input" followed by 2 underscores with some (1 to 7) random chars between. Thank you!
Examples:
input_7ax8_SOME_INFO
input_3f0max2_SOME_OTHER_INFO
input_k_ANOTHERINFO-any-chars-possible:0123456789
Using the detection of "non underscore" + "underscore" times 2 and fetching everything that comes after that you can get the result you ask.
The ?: is meant for not returning the result of the parts with underscores because the () are needed to combine it together.
$input = 'input_k_ANOTHERINFO-any-chars-possible:0123456789';
preg_match( '~^(?:[^_]+_){2}(.*)$~', $input, $match );
var_export($match);
You just need explode and its third param :
<?php
$input = 'input_7ax8_SOME_INFO';
$input = explode("_",$input,2); // Split 2 times
$input[2] = '<b>'.$input[2].'</b>'; // Make the rest of the string bold
$input = implode("_",$input); // re joining
echo $input;
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am looking for only vimeo id 95235223 from the complete link of http://vimeo.com/95235223.
How can I get it in php will trim function work or somthing else. I need help Please.
use parse_url(), like:
$url = "http://vimeo.com/95235223";
$parsed = parse_url($url);
$id = str_replace("/", "", $parsed["path"]);
echo $id; //gives 95235223
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am using this function which works fine for a single number entered by user in format 1000 and 1,100
function metersToSquareFeet($meters, $echo = true)
{
$m = $meters;
$valInFeet = $m*10.7639;
$valFeet = (int)$valInFeet;
if($echo == true)
{
echo $valFeet;
} else {
return $valFeet;
}
}
I need to modify for the case where users enter a range of numbers in the format: 1000-2000
The function should be smart enough to convert both numbers and in this case output in this format 10,763-21,527
You're going to need to parse the input yourself.
If you enter in 1000-2000 as a parameter it will think that it's -1000 as it will do the math.
I'm suggesting you change your input to either 2 parameters, an array or a string.
If using a string, use substring to find the int position of '-' http://us1.php.net/manual/en/function.substr.php or use explode like #crayonviolet suggested
Convert both numbers by your constant (10.7639)
Return your desired output as a string or as part of an array
Your choice depends on how your convertToSquareFeet function is used in other parts of your application and the code rework it would have by changing the parameter list.
Hope that helps!
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 file in a directory named 'achieve3000_Gestalt_students102713.txt'.. i want to reduce the file name to Gestalt_students ONLY
Have tried using explode() which gives something different altogether and preg replace
Please help
EDIT
i have 4 files
achieve3000_Gestalt_students102713.txt
achieve3000_Gestalt_teachers102713.txt
achieve3000_Perspectives_Middle_Academy_students102713.txt
achieve3000_Perspectives_Middle_Academy_teachers100913.txt
If the file name always begins with a character sequence whose length is equal to the length of "achieve3000_" (which is 12) and the number at the end is always 6 digits plus a 4 character extension sequence. The you can use this code
$output = substr($input, 12, strlen($input) - 22);
var_dump(substr('achieve3000_Gestalt_students102713.txt', 12, 16));
Did you try substr?
Like :
$input = "achieve3000_Gestalt_students102713.txt";
$answer =substr ($input, 12, 16);
echo $answer;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a String 7*10*6* I will separate the numbers, when I use explode function the out is:
Array
(
[0] => *
)
here is my code:
echo '<pre>';
print_r(explode('7*10*6','*'));
echo '</pre>';
what's the problem?
Oh boy, have you read the manual of explode?
the manual says:
explode(string $delimiter,string $string). You have done wrong. change your code to this:
print_r(explode('*','7*10*6'));
Try
print_r(explode('*','7*10*6'));
In explode function first argument is separator and second is string.