Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Wyrażenie regularne
patrysiek2
post
Post #1





Grupa: Zarejestrowani
Postów: 108
Pomógł: 5
Dołączył: 8.12.2011
Skąd: Łomża

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


Znowu problem i znowu z tym samym, czyli wyrażenia regularne ;/

Z tekstu:
Cytat
$tekst = '<a href="./memberlist.php?mode=viewprofile&u=123">Nick</a></td>';

chciałbym wyciągnąć liczbę (w typ przypadku '123'). Liczba ta jest zmienna więc wyciąganie wypadałoby zacząć od:
  1. viewprofile&u=

a skończyć na najbliższym ">.
Niestety nie udaje mi się :/

To takie moje zmagania z problemem:

  1. $tekst = '<a href="./memberlist.php?mode=viewprofile&u=680">ZmiennyNick</a></td>';
  2. preg_match_all('#href="[^"]*viewprofile&u=[0-9]*(\d+)*">$[^"]*"#', $tekst, $matches);


Proszę o pomoc w ułożeniu tego wyrażenia.

Ten post edytował patrysiek2 4.11.2013, 17:37:05


--------------------
if($problem == 1)
{
header("Location: http://www.forum.php.pl");
}
else
{
thinking();
}
Go to the top of the page
+Quote Post
Qss
post
Post #2





Grupa: Zarejestrowani
Postów: 141
Pomógł: 7
Dołączył: 22.02.2009

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


  1. preg_match_all('#href="(*.?)viewprofile&u=([0-9]+)">#', $tekst, $matches);


Ten post edytował Qss 4.11.2013, 17:51:35
Go to the top of the page
+Quote Post
patrysiek2
post
Post #3





Grupa: Zarejestrowani
Postów: 108
Pomógł: 5
Dołączył: 8.12.2011
Skąd: Łomża

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


Cytat(Qss @ 4.11.2013, 17:51:22 ) *
  1. preg_match_all('#href="(*.?)viewprofile&u=([0-9]+)">#', $tekst, $matches);


Warning: preg_match_all(): Compilation failed: nothing to repeat at offset 7 in /home/u251142990/public_html/func.php on line 72

A tak wygląda całość:
  1. function user_id($u_nick)
  2. {
  3. $config['address'] = 'http://forum.taern.pl/';
  4. $path['cookie'] = dirname(__FILE__).'/cookies.txt';
  5.  
  6. $post['username'] = 'dsgbw';
  7. $post['password'] = '***';
  8. $post['redirect'] = 'value="./memberlist.php?username="'.$u_nick;
  9. $post['login'] = 'Zaloguj się';
  10.  
  11.  
  12. $ch = curl_init($config['address'].'memberlist.php?username='.$u_nick);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_HEADER, true);
  15. curl_setopt($ch, CURLOPT_COOKIEFILE, $path['cookie']);
  16. curl_setopt($ch, CURLOPT_COOKIEJAR, $path['cookie']);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS, prepare_request($post));
  18.  
  19. $page = curl_exec($ch);
  20. curl_close($ch);
  21.  
  22. $tekst = '<a href="./memberlist.php?mode=viewprofile&u=680">ZmiennyNick</a></td>';
  23. preg_match_all('#href="(*.?)viewprofile&u=([0-9]+)">#', $tekst, $matches);
  24. print_r($matches);
  25. }


Chcę 'wycinać' tą liczbę ze zmiennej $page jbc.


--------------------
if($problem == 1)
{
header("Location: http://www.forum.php.pl");
}
else
{
thinking();
}
Go to the top of the page
+Quote Post
Qss
post
Post #4





Grupa: Zarejestrowani
Postów: 141
Pomógł: 7
Dołączył: 22.02.2009

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


zawsze mi sie myli ;D nie
  1. (*.?)

tylko
  1. (.*?)
Go to the top of the page
+Quote Post
patrysiek2
post
Post #5





Grupa: Zarejestrowani
Postów: 108
Pomógł: 5
Dołączył: 8.12.2011
Skąd: Łomża

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


Cytat(Qss @ 4.11.2013, 18:24:50 ) *
zawsze mi sie myli ;D nie
  1. (*.?)

tylko
  1. (.*?)


Zmieniłem i pobierając ze zmiennej $tekst działa, ale jak daje to aby pobierało ze strony (cURL) to lipka :/
  1. function user_id($u_nick)
  2. {
  3. $config['address'] = 'http://forum.taern.pl/';
  4. $path['cookie'] = dirname(__FILE__).'/cookies.txt';
  5.  
  6. $post['username'] = 'dsgbw';
  7. $post['password'] = '**';
  8. $post['redirect'] = 'value="./memberlist.php?username="'.$u_nick;
  9. $post['login'] = 'Zaloguj się';
  10.  
  11.  
  12. $ch = curl_init($config['address'].'memberlist.php?username='.$u_nick);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_HEADER, true);
  15. curl_setopt($ch, CURLOPT_COOKIEFILE, $path['cookie']);
  16. curl_setopt($ch, CURLOPT_COOKIEJAR, $path['cookie']);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS, prepare_request($post));
  18.  
  19. $page = curl_exec($ch);
  20. curl_close($ch);
  21. preg_match_all('#href="(.*?)viewprofile&u=([0-9]+)">#', $page, $matches);
  22. //print_r($matches[1][0]);
  23. print_r($matches);
  24. }


Ten post edytował patrysiek2 4.11.2013, 18:35:16


--------------------
if($problem == 1)
{
header("Location: http://www.forum.php.pl");
}
else
{
thinking();
}
Go to the top of the page
+Quote Post
Qss
post
Post #6





Grupa: Zarejestrowani
Postów: 141
Pomógł: 7
Dołączył: 22.02.2009

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


wyświetl page i zobacz czy na pewno dobrze się pobrało i ewentualnie dodaj flagę m
  1. preg_match_all('#href="(.*?)viewprofile&u=([0-9]+)">#m', $page, $matches);
Go to the top of the page
+Quote Post
patrysiek2
post
Post #7





Grupa: Zarejestrowani
Postów: 108
Pomógł: 5
Dołączył: 8.12.2011
Skąd: Łomża

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


Głupota ludzka biggrin.gif
Nie:
  1. viewprofile&u=

Lecz:
  1. viewprofile&amp;u=


Problem rozwiązany, thx za pomoc.
Moja rada : nie "badajcie elementu" podczas pisania wyrażeń regularnych lecz 100% źródło strony biggrin.gif


--------------------
if($problem == 1)
{
header("Location: http://www.forum.php.pl");
}
else
{
thinking();
}
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 Aktualny czas: 19.08.2025 - 07:32