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
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$out_terms[$term->name] = '' . $text . '';
Please help me check where the code gone wrong,any missing notes etc,as I am really 0 into php
$out_terms[$term->name] = sprintf('%s', $term_link, $text);
Try this (best construct) :
$out_terms[$term->name] = "$text";
or :
$out_terms[$term->name] = ''.$text.'';
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
Hi all i am looking for a simple way to check if a string equals an url like this:
http://youtu.be/WWQZ046NeUA
To convert it to a proper youtube url like this:
http://www.youtube.com/watch?v=WWQZ046NeUA
If not to leave it alone, what's the simplest way to do it in php?
You can use this preg_replace call:
$u = 'http://youtu.be/WWQZ046NeUA';
$r = preg_replace('~^https?://youtu\.be/([a-z\d]+)$~i', 'http://www.youtube.com/watch?v=$1', $u);
str_replace should work wonders.
$url = ''; //url you're checking
$ytshorturl = 'youtu.be/';
$ytlongurl = 'www.youtube.com/watch?v=';
if (strpos($url,$yturl) !== false) {
$url = str_replace($ytshorturl, $ytlongurl, $url);
}
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];
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.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I don't know exactly how to say this, I'll use an example.
//[$var:Username|n] will print username with n length
$myText = 'The participants are [$var:Username|10], [$var:Username|8], and [$var:Username|6]';
$username = array('Alexandrite', 'Maximillian', 'Angelina');
$result = someFunction('[$var:Username|n]', $username, $myText);
echo $result;
//The participants are Alexandrit, Maximill, and Angeli
Any idea how to do this? Maybe using preg_replace?
I'm interested to know why you would even need to do this. Regardless:
preg_replace_callback('/\[\$var:Username\|(\d+)\]/', function ($match)
use (&$count, $username
) {
return substr($username[$count++], 0, $match[1]);
}, $myText);