basically the problem is i have an array of english words and spanish words. i then need to parse a page of html to find any english words and replace them with the spanish equivalent. i was using preg_match firstly to check if the english word was a whole word i.e. not in quotes or next to another character e.g. style= but at the same time need to be able to allow for style. (period)
do you think im going about this the right way? am i making this more complicated than it has to be?
any pointers would be great
heres the code i have so far
//if the forms submitted take the 3 fields: english, spanish and content to check
if(isset($_POST['submitted'])) {
$search = explode("\n",$_POST['search']);
$replace = explode("\n",$_POST['replace']);
$content = $_POST['haystack'];
$sr = array_combine($search,$replace);
//create arrays for preg_replace
foreach ($sr as $key => $value) {
$patterns[] = $key;
$replacements[] = $value;
}
$newcontent = preg_replace($patterns,$replacements,$content);
echo $newcontent;
}
When I run this I get a Delimiter must not be alphanumeric or backslash in ../index.php on line 21 error
Line 21 is $newcontent = preg_replace($patterns,$replacements,$content);