Jump to content
php.lv forumi
  • 0

Smiles


Kaspars Silins

Question

nezinu vai rakstu pareizajā kategorījā, bet man vajaga domāju ka tas varētu būt java scripts, attiecīgā simbolu vietā rādās smaidiņš, piemēram kā tas ir visos forumos.. :) meklēju google, bet kautkā neatradu, vai nemācēju atrast, varbūt kādam ir pa rokai kāds scripts, vai javascripts, kur var redzēt piemēru.. ;(

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0
$teksts = 'lalala :)) lalala :)';
echo str_replace(array(':))', ':)'), array('<img src="/images/smile/lolol.gif" alt="" />', '<img src="/images/smile/lol.gif" alt="" />'), $teksts);

ar javascript to arī var, taču ar php ir vieglāk ;)

Edited by 2easy
Link to comment
Share on other sites

  • 0
<?
function smile($txt=''){
$smile = array(
':)'=>'smile',
':-)'=>'smile',
':-]'=>'smile',
':*'=>'kiss',
':D'=>'laught',
':P'=>'tangue'
);
foreach($smile as $key=>$img){ $txt = str_replace($key,'<img src="/images/smiles/'.$img.'.gif">',$txt); }
return $txt;
}


$text = 'Čau sauļuk :*, ļoti ilgojos :):*';

echo smile($text);
// Čau sauļuk <img src="/images/smiles/kiss.gif">, ļoti ilgojos <img src="/images/smiles/smile.gif"><img src="/images/smiles/kiss.gif">
?>

Edited by EdgarsA
Link to comment
Share on other sites

  • 0

emm man maza problēmiņa.

skripts gan ir mazliet cits bet smailiju f-ja līdzīga

 

$smilies = array(
	  ":)" => "smile2.gif",
	  ":D" => "grin.gif",
	  ":p" => "tongue.gif",
	  ":/" => "confused.gif",
	  ":(" => "sad.gif",
	  ";(" => "weep.gif",
	  ":o" => "blink.gif",
	  "8)" => "cool1.gif",
	  "(blush)" => "blush.gif",
	  "(love)" => "wub.gif",
	  "(hello)" => "wave.gif",
	  ":@" => "rant.gif",
	  ":x" => "nugget.gif",
	  "(inlove)" => "lovers.gif",
	  ":*" => "kissing2.gif",
	  "(devil)" => "devil.gif",
	  "o.O" => "crazy.gif",
	  "(stupid)" => "chair.gif",
	  "(beer)" => "beer2.gif",
	);

	reset($smilies);
	while (list($code, $url) = each($smilies))
	$s = str_replace($code, "<img border=0 src=\"http://filmam.lv/images/smilies/$url\" title=\"". htmlspecialchars($code) ."\" alt=\"" . htmlspecialchars($code) . "\">", $s);

 

bet pie izvades iegūstu:

://filmam.lv/images/smilies/smile2.gif" title=":)" alt=":)">

 

kas viņam http nepatīk?

 

EDIT: jaunā versija, bet rāda tikai to confused smaidiņu :/

$urlis = 'http://filmam.lv';
reset($smilies);
while (list($code, $url) = each($smilies))
$s = str_replace($code, "<img border=0 src=\"".htmlspecialchars($urlis)."/images/smilies/".htmlspecialchars($url)."\" title=\"". htmlspecialchars($code) ."\" alt=\"" . htmlspecialchars($code) . "\">", $s);

Edited by eT`
Link to comment
Share on other sites

  • 0

$smilies = array(
":)" => "smile2.gif",
":D" => "grin.gif",
":p" => "tongue.gif",
":/" => "confused.gif",
":(" => "sad.gif",
";(" => "weep.gif",
":o" => "blink.gif",
"8)" => "cool1.gif",
"(blush)" => "blush.gif",
"(love)" => "wub.gif",
"(hello)" => "wave.gif",
":@" => "rant.gif",
":x" => "nugget.gif",
"(inlove)" => "lovers.gif",
":*" => "kissing2.gif",
"(devil)" => "devil.gif",
"o.O" => "crazy.gif",
"(stupid)" => "chair.gif",
"(beer)" => "beer2.gif",
);
reset($smilies);
while (list($code, $url) = each($smilies)){
$img = '<img border="0" src="%s" title="%s" alt="%s">'; 
$s = str_replace($code, sprintf($img,$url,htmlspecialchars($code),htmlspecialchars($code)),$s);
}
$url = "http://filmam.lv/images/smilies/";
$s = str_replace('src="','src="'.$url,$s);

 

iemesls tam bija $url = "http://filmam.lv/images/smilies/";

Link to comment
Share on other sites

  • 0

šādām transformācijām/repleisiem iesaku izmantot strtr()

strtr() will always look for the longest possible match first and will *NOT* try to replace stuff that it has already worked on
ļoti palīdz, kad vajag izvairīties no vairākkārtīgas repleisošanas. turklāt nekādu for ciklu nevajag. tikai padod array ar mappingu Edited by 2easy
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
Answer this question...

×   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...