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.
Related
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
While trying to echo out a line, get an unexpected error for the following line:
echo "$arr[count($arr)]".')';
Cannot figure out what the fix might be. Want to print out the last item of the array.
Remove quotes and remember that array index starts from zero.
echo $arr[count($arr) - 1];
Or just:
echo end($arr);
try this:
echo '('.$arr[count($arr)].')';
Try this:
echo $arr[count($arr)];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm trying to find a text between $something and $something_else and ditch it out in an array.
I would think you need preg_match to do this but I have been trying alot and still have no idea.
This should work no matter what $something and $something_else is.
You need to read the documentation of preg_match and preg_match_all.
Here's a simple example that will match whatever content inside (double quotes)..
<?php
preg_match_all('~"(.*?)"~',
'Hey there "I will be matched", because "I am inside the double quotes"',
$out, PREG_PATTERN_ORDER);
print_r(($out[0]));
OUTPUT :
Array
(
[0] => "I will be matched"
[1] => "I am inside the double quotes"
)
Correct me if i am wrong. We can use explode one string into a array. Use pre_match_all for the another string with each word of the array . In this way, it will work with any 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
Can anyone help me get the value of IFC/USD 0.00001031 from the webpage http://infinitecoin.com.
I need to grab the value after IFC/USD..
The way I thought to do it was to:
$file_string = file_get_contents('http://infinitecoin.com');
preg_match('/IFC/USD plus next 11 charecters', $file_string, $title);
$value = $title[1];
echo $title_out ;
But im not sure how to ask PHP to find IFC/USD then return the next 11 characters after that.
If I could accomplish this, my task would be solved..
Any help would be great.
Thank you
Jason
$output = array();
preg_match("/(?<=IFC\/USD\s)[\d\.]+/", 'IFC/USD 0.00001015', $output);
$output will look like this:
Array
(
[0] => 0.00001015
)
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];