html - how can i stop some words/letters from being swapped in php? -
i using php swap text 1 textarea , display in another, , of works, sadly parts dont.
i using str_ireplace
, far, 60 different words, many more come. couple of examples of problem are:
old - auld old man - gadgie
if above, first word unswapped , second new word. however, if put old man in text, come "auld man" instead of "gadgie".
i know may because have declared "old-auld" before "old man - gadgie"
but problem that:
yes - aye no - nar
again, first word original, second after swap. if write "yesterday" displayed "ayeterday" or if had "nose" "narse"
is there anyway change "yes" on own , not if part of word?
and there way have "old man" , "old" separate replacements?
hope makes sense
my code str_ireplace
:
<form method="post" action="post.php" > <textarea name="status2" cols="50" rows="5"/> <?php echo str_ireplace(array ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots','came','nice','cold','church','clothes','stick','dirty','clever','cloth','cow','crow','stool','crown','pigeon','dad','darlington','dead','do','devil','dont','do not','durham','down','drown','punch','ditch','eye','fall','trouble','condition','four','stupid','old man','go','going','jumper','give over','grandad','hold','get away','home'), array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts','cam','canny','card','chorch','claes','clag','clarty','clivvor','cloot','coo','craa','cracket','croon','cushat','da','darlo','deed','dee','deil','divvent','divvent','dorham','doon','droon','dunsh','dyke','eee','faa','fash','fettle','fower','gaumless','gadgie','gan','gannin','ganzie','giveower','granda','haad','hadaway','hyem'),$status); ?> </textarea><br>
as said, there 60+ words.
i didn't add code thought may not have been relevant.
about first part. should replace more specific word first. i.e "old man", , "man" or use strtr
<?php $trans = array("h" => "-", "hello" => "hi", "hi" => "hello"); echo strtr("hi all, said hello", $trans); ?> above example output: hello all, said hi
about whole words. may regexps (and \b
in particularly)
Comments
Post a Comment