Ashura: Gradzeichen mit preg_replace ersetzen?

Beitrag lesen

Hallo Thorsten.

Das ist mein Array [0] => Temperature: 86°F / 30°C

[…]
Allerdings brauche ich das ganze nur als "30", also ohne das ° Symbol.

Also folgendermaßen?

<?php  
  
error_reporting(E_ALL);  
header('content-type: text/plain; charset=utf-8');  
setlocale(LC_ALL, 'de_DE.UTF-8', 'ge');  
  
$str_temp = 'Temperature: 86°F / 30°C';  
$str_end = '°C';  
$str_start =' / ';  
  
$int_end = strpos($str_temp, $str_end);  
$int_start = strpos($str_temp, $str_start);  
  
if ($int_end !== false and $int_start !== false) {  
  
  $int_end -= strlen($str_temp);  
  $int_start += strlen($str_start);  
  
  $str_temp = substr($str_temp, $int_start, $int_end);  
  
}  
  
echo $str_temp; // 30  
  
?>

Es muss nicht immer ein regulärer Ausdruck sein.

Einen schönen Mittwoch noch.

Gruß, Ashura

--
sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
„It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
[HTML Design Constraints: Logical Markup]