Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1

    Prelevare numeri da stringa

    CIao.

    se io ho una stringa "123stringablabla", come faccio a prelevare le prime cifre numeri? cioč devo prelevare cominciando dalla prima cifra, finchč sono numeri;


    come la faccio una cosa del genere? espressione regolare?
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    595
    Codice PHP:
    $stringa "123stringablabla";
    preg_match("/^[0-9]*/",$stringa,$match);
    echo 
    $match[0]; 

  3. #3
    Se le cifre sono all'inizio della stringa credo basti fare un cast esplicito ad integer/float tipo:
    Codice PHP:
    echo (int)"123stringablabla";
    echo (float)
    "123.4stringablabla"
    dA .. foto di viaggio
    L'esperienza č il tipo di insegnante pių difficile.
    Prima ti fa l'esame, e poi ti spiega la lezione.

  4. #4
    Originariamente inviato da Leilond
    Codice PHP:
    $stringa "123stringablabla";
    preg_match("/^[0-9]*/",$stringa,$match);
    echo 
    $match[0]; 

    gentile funziona perfettamente. Un ultima cosa, se volessi stampare anche la striga restante senza pių i numeri?
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  5. #5
    up
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  6. #6
    ho provato una cosa cosė ma non funge...

    Codice PHP:
    $stringa2 $_POST[DepEquip];
    $pattern "/[0-9]/"
    echo 
    "la stringa č".preg_replace($pattern,"",$stringa2); 
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  7. #7
    Originariamente inviato da Manuelandro
    gentile funziona perfettamente. Un ultima cosa, se volessi stampare anche la striga restante senza pių i numeri?
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  8. #8
    a malincuore uppo ancora ma mi serve assolutamente questa cosa...
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  9. #9
    Codice PHP:
    $stringa $_POST['DepEquip'];
    $pattern '/^(\\d+)(.*)$/';
    preg_match($pattern,$stringa,$mth);
    print_r($mth); 
    cosė dovrebbe fare quello che chiedi
    dA .. foto di viaggio
    L'esperienza č il tipo di insegnante pių difficile.
    Prima ti fa l'esame, e poi ti spiega la lezione.

  10. #10
    nu

    stampa questo...

    Codice PHP:
    Array ( [0] => 20 [1] => 20 [2] => ) 
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.