i have a large text variable. some of this variable is:

$text="A aSite Browse'a option has been added. This allows you to browse a FTP server while transferring and add files to the queue. It uses a asecond connection'a to browse, so you must be able to connect to the site twice for thisto work.";

as you see it has some mistaks. all mistaks like each others.

as example this is incorrect: A aSite Browse'a option
correct is: A «Site Browse» option

alse expamle in line 2 this is incorrcet: uses a asecond connection'a to browse
correct is: uses a «second connection» to browse

all mistkas end of to: "'a "
that must replace with: "» "

then some characters before "'a " there is: " a"
that must replace:" «"
(in other mean if finds "'a " then first happen of " a" character before it must replace with " «"

i taked many times and i cannot write one script to solve this problem for correcting text file.

i writed this part of script:

for ($i=0; $i<strlen($text); $i++){
		$char = substr($num, $i, 1);
		$nextchar = @substr($num,$i+1,1);
		$secondchar = @substr($num,$i+2,1);

	if (($char == "'") && ($nextchar=='a') && ($secondchar==' ')) {

	// here must replace "'a " with "&#187; "

	// here must script go back some characters until to find " a" and replease it with " &#171;"

	$i++;
	$i++;
	}
}

any one can help me and take a time to solving this problem or copmpleting this script?

many many thanks

    This is the best I can think of, but it may run into problems if there are multiple words starting with "a" in the same phrase.

    $text = preg_replace('/\ba(\S[a-zA-Z\s]*)\'a\b/Us', '&#171;\\1&#187;', $text);
    
      Write a Reply...