Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [REGEX] Problem z pobraniem ostatniego stringa w ciągu
kuna11
post 30.07.2016, 19:32:49
Post #1





Grupa: Zarejestrowani
Postów: 93
Pomógł: 0
Dołączył: 15.09.2013

Ostrzeżenie: (0%)
-----


Chcę pobrać z linka YT:
https://www.youtube.com/watch?v=kOkQ4T5WO9E
to co jest po 'v='

Napisałem:
  1. $content='https://www.youtube.com/watch?v=kOkQ4T5WO9E';
  2. $keyreg = '/https:\/\/www.youtube.com\/watch\?v=(.+?)/';
  3. preg_match_all($keyreg, $content, $key);
  4. print_r($key);

No i wyciąga mi tylko pierwszy znak 'k' a przecież (.+?) odpowiada za wszystko co jest potem questionmark.gif?

Dlaczego to nie działa ?
Go to the top of the page
+Quote Post
markuz
post 30.07.2016, 19:43:20
Post #2





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

Ostrzeżenie: (0%)
-----


  1. preg_match_all("/v=(.+)/", $input_lines, $output_array);

http://stackoverflow.com/questions/9623879...x-question-mark - tu znajdziesz odpowiedź na swoje pytanie. Gdybyś nie mógł to zacytuję:
Cytat
Yes. + and * are called "greedy" operators: they consume as much as they can get away with. In contrast, +? and *? are the "non-greedy" versions: they consume as little as they can get away with. Search on the web for "regex greedy nongreedy" for more information/tutorials.


Ten post edytował markuz 30.07.2016, 19:46:22


--------------------
Go to the top of the page
+Quote Post
kuna11
post 30.07.2016, 19:58:09
Post #3





Grupa: Zarejestrowani
Postów: 93
Pomógł: 0
Dołączył: 15.09.2013

Ostrzeżenie: (0%)
-----


Aha zachłanność smile.gif Dzięki !
Go to the top of the page
+Quote Post
trueblue
post 30.07.2016, 20:02:46
Post #4





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. $content='https://www.youtube.com/watch?v=kOkQ4T5WO9E';
  2. parse_str(parse_url($content,PHP_URL_QUERY),$output);
  3. echo $output['v'];



--------------------
Go to the top of the page
+Quote Post
kuna11
post 30.07.2016, 20:05:10
Post #5





Grupa: Zarejestrowani
Postów: 93
Pomógł: 0
Dołączył: 15.09.2013

Ostrzeżenie: (0%)
-----


Ciekawa alternatywa smile.gif
Go to the top of the page
+Quote Post
mlawnik
post 30.07.2016, 23:46:16
Post #6





Grupa: Zarejestrowani
Postów: 455
Pomógł: 49
Dołączył: 12.04.2010

Ostrzeżenie: (0%)
-----


Na pewno szybsza.


--------------------
Pozdrawiam,
mlawnik

Cytat(nospor)
Jedzmy gówno.... miliony much nie może się przecież mylić
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.06.2025 - 22:00