Jump to content
php.lv forumi

Meklēju "Uzmini vārdu!" skriptu/php klasi


torrentz

Recommended Posts

Gadījās problēma. PHP tā īsti nedraudzējas ar UTF-8:

 

Ja, vārds ir ar kirilicas burtiem, piemēram: барбамил, tad šis kods

 

 $ran_1 = rand(0, $cik);
$ran_2 = rand(0, $cik);
$ran_3 = rand(0, $cik);
$ran_4 = rand(0, $cik);
$ran_5 = rand(0, $cik);
$ran_6 = rand(0, $cik);
$ran_7 = rand(0, $cik);
$ran_8 = rand(0, $cik);
$ran_9 = rand(0, $cik);

				$vards = str_replace(  $atb[$ran_1], "-", $ottt );
				$vards = str_replace($vards[$ran_2], "-", $vards);
				$vards = str_replace($vards[$ran_3], "-", $vards);
				$vards = str_replace($vards[$ran_4], "-", $vards);
if($cik >= 5) $vards = str_replace($vards[$ran_5], "-", $vards);
if($cik >= 6) $vards = str_replace($vards[$ran_6], "-", $vards);
if($cik >= 7) $vards = str_replace($vards[$ran_7], "-", $vards);
if($cik >= 8) $vards = str_replace($vards[$ran_8], "-", $vards);
if($cik >= 9) $vards = str_replace($vards[$ran_9], "-", $vards);

 

echo $vards; izvadās kā

 

----�------�----

 

Laikm PHP nemāk sadalīt vārdu kā pseidomasīvu (vārdu sadalīt pa burtiem), ja tas ir multibaitīgais vārds...

 

Ir kādas idejas?

Edited by torrentz
Link to comment
Share on other sites

"вицин" vēljoprojām pārvēršas par: "----�-----"

 

 $cik	 = mb_strlen($ottt)-1;
$ran_1 = rand(0, $cik);
$ran_2 = rand(0, $cik);
$ran_3 = rand(0, $cik);
$ran_4 = rand(0, $cik);
$ran_5 = rand(0, $cik);
$ran_6 = rand(0, $cik);
$ran_7 = rand(0, $cik);
$ran_8 = rand(0, $cik);
$ran_9 = rand(0, $cik);

				$vards = str_replace(mb_substr($ottt,  $ran_1, 1),   "-", $ottt );
				$vards = str_replace(mb_substr($vards, $ran_2, 1), "-", $vards);
				$vards = str_replace(mb_substr($vards, $ran_3, 1), "-", $vards);
				$vards = str_replace(mb_substr($vards, $ran_4, 1), "-", $vards);
if($cik >= 5) $vards = str_replace(mb_substr($vards, $ran_5, 1), "-", $vards);
if($cik >= 6) $vards = str_replace(mb_substr($vards, $ran_6, 1), "-", $vards);
if($cik >= 7) $vards = str_replace(mb_substr($vards, $ran_7, 1), "-", $vards);
if($cik >= 8) $vards = str_replace(mb_substr($vards, $ran_8, 1), "-", $vards);
if($cik >= 9) $vards = str_replace(mb_substr($vards, $ran_9, 1), "-", $vards);

Link to comment
Share on other sites

Ārprāc, es laikam nojūgšos- pat šis nestrādā:

 

 $ran_1 = rand(0, $cik);
$ran_2 = rand(0, $cik);
$ran_3 = rand(0, $cik);
$ran_4 = rand(0, $cik);
$ran_5 = rand(0, $cik);
$ran_6 = rand(0, $cik);
$ran_7 = rand(0, $cik);
$ran_8 = rand(0, $cik);
$ran_9 = rand(0, $cik);

function mb_str_replace($haystack, $search,$replace, $offset=0,$encoding='auto'){
$len_sch=mb_strlen($search,$encoding);
$len_rep=mb_strlen($replace,$encoding);

while (($offset=mb_strpos($haystack,$search,$offset,$encoding))!==false){
	$haystack=mb_substr($haystack,0,$offset,$encoding)
		.$replace
		.mb_substr($haystack,$offset+$len_sch,strlen($haystack),$encoding);
	$offset=$offset+$len_rep;
	if ($offset>mb_strlen($haystack,$encoding))break;
}
return $haystack;
}

		   $vards = mb_str_replace($ottt,  mb_substr($ottt,  $ran_1, 1), "-");
		   $vards = mb_str_replace($vards, mb_substr($vards, $ran_2, 1), "-");
		   $vards = mb_str_replace($vards, mb_substr($vards, $ran_3, 1), "-");
		   $vards = mb_str_replace($vards, mb_substr($vards, $ran_4, 1), "-");
if($cik >= 5) $vards = mb_str_replace($vards, mb_substr($vards, $ran_5, 1), "-");
if($cik >= 6) $vards = mb_str_replace($vards, mb_substr($vards, $ran_6, 1), "-");
if($cik >= 7) $vards = mb_str_replace($vards, mb_substr($vards, $ran_7, 1), "-");
if($cik >= 8) $vards = mb_str_replace($vards, mb_substr($vards, $ran_8, 1), "-");
if($cik >= 9) $vards = mb_str_replace($vards, mb_substr($vards, $ran_9, 1), "-");

Link to comment
Share on other sites

Apnika čakarēties ar PHP un UTF-8; no sākuma pārkonvertēju uz cp1251, tad izmantoju parastās funkcijas un pēc tam konvertēju atpakaļ uz UTF-8...

 

$ottt  = iconv("UTF-8", "CP1251", $ottt);
blablabla...
$vards = iconv("CP1251", "UTF-8", $vards);

Edited by torrentz
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...