PHP-Code:
$url = explode('.', $url, 2);
echo implode($zahl.'.', $url);
$url = 'http://thirdlevel.example.com';
$zahl = 2;
$firstdot = strpos($url, '.');
echo substr($url, 0, $firstdot).$zahl.substr($url, $firstdot);
<?php
$url = "http://thirdlevel.example.com";
$zahl = 2;
$regex = "!http:\/\/(\w+)\.!eU";
$url_new = preg_replace($regex, '$1."$zahl"', $url);
echo $url_new; // gibt "thirdlevel2example.com" aus.
?>
<?php
$url = "http://thirdlevel.example.com";
$zahl = 2.".";
$regex = "!http://(w+)[.]!e";
$url_new = preg_replace($regex, '$1.$zahl', $url);
echo $url_new;
?>
<?php
$url = "http://thirdlevel.example.com";
//...
echo $url_new; // gibt "http://thirdlevel2.example.com" aus
?>
<?php
$url = "http://thirdlevel.example.com";
$zahl = 2;
$regex = "![url]http://[/url](\w+)[.]!";
$url_new = preg_replace($regex, "$1".$zahl, $url);
echo $url_new; // gibt leider nur "example.com" aus.
?>
Einen Kommentar schreiben: