Jump to content
php.lv forumi

Lai pedējos simbolus aizstāv ar *


homers

Recommended Posts

pēdējos 3 ciparus varētu "aizstāvēt" šādi

$a = array('84.237.205.8', '84.237.205.88', '84.237.205.888');
foreach ($a as $v) echo substr($v, 0, -3) . '***' . '<br />';
/*
84.237.20***
84.237.205***
84.237.205.***
*/

bet tā kā ip adreses pēdējā daļā var būt 1..3 cipari, tad pareizi būtu aizstāt visu daļu, nevis kkādu fiksētu ciparu skaitu

$a = array('84.237.205.8', '84.237.205.88', '84.237.205.888');
foreach ($a as $v) {
$aIp = explode('.', $v);
$aIp[3] = '***';
echo implode('.', $aIp) . '<br />';
}
/*
84.237.205.***
84.237.205.***
84.237.205.***
*/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...