Autor Zpráva
Weat...
Profil *
Dobrý den, právě již dokončuji poslední část své aplikace, ale poteboval bych jeste poradit jak vyjmout číselnou hodnotu ze retezce v promene ktery ziskavam z xml
Vzor. Wind: North at 13 mp/h

Takže potebuji vyjmout jakoukoliv ciselnou hodnotu
pak sni provist vypocet a vysledek vratit na stejné místo od kud pochazi.

Předem děkuji za radu.
Tori
Profil
Použila bych nejspíš preg_replace_callback.
Weat...
Profil *
Dobrý večer, mohl bych poprosit o popisky k tomuto a jestli by to po prepsani mohlo fungovat u daneho zameru viz.nahore
preg_replace_callback( "/[0-9]*/", array( &$this, '_getPHPNumber' ), $code );

private function _getPHPNumber( $matches ) {
    return ( $this->_getHtmlCode( $matches[0], PHP::$Colors['number'] ) );
}

private function _getHtmlCode( $text, $color ) {
    $rows = array_filter( explode( "\n", $text ), 'is_string' );
    $count = count( $rows );
    $output = '';

    for ( $i = 0; $i < $count; $i++ ) {
        $n = ( $count > 1 ? ( $i != $count - 1 ? "\n" : "" ) : "" );
        $output .= "<span style=\"color:{$color};\">{$rows[$i]}</span>{$n}";

    }

    return ( $output );
}
Weat...
Profil *
Vyrešeno jinak...
$windb = "Wind: North at 13 mp/h";
$windc = Str_Replace(
                        Array(" ","á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","/",":","y","z","q","w","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Y","Z") ,
                        Array("",) ,
                        $windb);
  if ($windc >= 1) {
    $vysledek = $windc * 1.609344;
  }
  else {
    $vysledek = $windc / 0.6213712;
  } 
 echo "".$vysledek.""; 
Tori
Profil
Weat...:
Případně místo toho str_replace: $windc = preg_replace('~\D+~', '', $windb);

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: