Recent Topics

[Almost solved] minor issue in texturize plugin

started by on Oct 23, 2007 – Last touched: Oct 23, 2007

Oct 23, 2007 16:41    

See: [url=http://forums.b2evolution.net/viewtopic.php?t=13069&start=0&postdays=0&postorder=asc&highlight=][1.10.x] Quotation marks conversion from "ticks"[/url].

Please do change CSV.

Thanks,

ƒ

Oct 23, 2007 18:54

Come up with the bullet proof answer and I'll make the changes ;)

¥

Oct 24, 2007 01:49

PHP

$curl preg_replace('/"(\s|\Z|[\.,\?!;:\)\]}]\s|[\.,\?!;:\)\]}]\Z)/''& #8221;$1'$curl);

minus the space after &
and

PHP

$curl preg_replace("/'(\s|\Z|[\.,\?!;:\)\]}]\s|[\.,\?!;:\)\]}]\Z)/"'& #8217;$1'$curl);

once again minus the space after &.

This seems to work just fine but any feedback is appreciated.

ƒ

Oct 24, 2007 11:18

You could probably ( untested of course ;) ) reduce both those to :

PHP

$curl preg_replace('/["\'](\s|\Z|[\.,\?!;:\)\]}]\s|[\.,\?!;:\)\]}]\Z)/''& #8221;$1'$curl);

I'd need to have a play with some sample data to be sure it all works as expected ;)

¥

Oct 24, 2007 13:04

I was wonderimng if this works:

PHP

$curl preg_replace("/'(\s|\Z|[\.,\?!;:\)\]}][\s\Z])/"'& #8217;$1'$curl);

Oct 24, 2007 13:43

This is a few characters shorter and it still works:

PHP

$curl preg_replace('/"([\.,\?!;:\)\]}]?[\s\Z])/''& #8217;$1'$curl);

It doesn't come mutch leaner than this unless you do:

PHP

$curl preg_replace('/"(.?[\s\Z])/''& #8217;$1'$curl);

--ƒ

Oct 24, 2007 13:47

I am fascinated by this, but you may have noticed. :lol:

--ƒ

Oct 24, 2007 15:03

Hi Afwas,
Compare the two outputs :

PHP

<?php
$fred '"hello world!", said "Fred". Unfortunately he\'d a problem of thinking of a sentence that involved ";" so he "went home";-p';
 
$peter preg_replacearray(
    '~((\w)["\'](\W))|((\W)["\'](\w))|((\W)["\'](\W))~'// find any " or ' within sentance
    '~^["\']~'// find any " or ' at start of line
    '~["\']$~' // find any " or ' at end of line
     ) ,array'$2$5$8<quote>$3$6$9''<quote>''<quote>' ), $fred );
 
$john  preg_replace('/"([\.,\?!;:\)\]\}]?[\s\Z])/''<quote>$1'$fred); 
echo 'Peter : '.$peter.'<br />John : '.$john;
?>

Code

Peter : <quote>hello world!<quote>, said <quote>Fred<quote>. Unfortunately he'd a problem of thinking of a sentence that involved <quote>;" so he <quote>went home<quote>;-p
John : "hello world!<quote>, said "Fred<quote>. Unfortunately he'd a problem of thinking of a sentence that involved ";<quote> so he "went home";-p

¥

Oct 24, 2007 16:08

¥åßßå wrote:

Hi Afwas,
Compare the two outputs :

¥

We're talking *closing* quotation marks only. The second example looks ok, but it misses the last " and it should because there is no space or end of string after ; but a -. If you insert a space before -p it should find the last quote also.

--ƒ

Oct 24, 2007 16:37

Ah, now you make sense .... can you tell I don't use the texturiser plugin? :roll:

How about a combination of the two ;)

PHP

echo preg_replace('/("([\.,\?!;:\)\]}]?[\s\Z]))|(\w)"(\W)/''$3[quote]$2$4'$fred);

¥

*edit*
or

PHP

preg_replace('/("(\W?[\s\Z]))|(\w)"(\W)/''$3[quote]$2$4'$fred);

Oct 24, 2007 19:30

¥åßßå wrote:

Ah, now you make sense ....

I do not agree with you. I made sense all along.
¥åßßå wrote:

can you tell I don't use the texturiser plugin? :roll:

You should:

PHP

$cockney = array ("'tain't""'twere""'twas""'tis","'twill""'til""'bout""'nuff""'round");
$cockneyreplace = array ("’tain’t""’twere""’twas""’tis""’twill""’til""’bout""’nuff""’round");
$curl str_replace($cockney$cockneyreplace$curl);

Your last example is about the right combination of grace and functionality, but I could live without the (\w)"(\W)
and even with .? in stead of \W? and -perhaps- even (\w)" in stead of (\w)"(\W)

--ƒ

*edit*
how 'bout:

PHP

(\w)(\W)"(\W)

I start to dislike phpBB:
(\w)(\W)"(\W)

Oct 24, 2007 19:50

Afwas wrote:

¥åßßå wrote:

Ah, now you make sense ....

I do not agree with you. I made sense all along.

You need to learn blonde :P

Afwas wrote:

You should:

PHP

$cockney = array ("'tain't""'twere""'twas""'tis","'twill""'til""'bout""'nuff""'round");
$cockneyreplace = array ("’tain’t""’twere""’twas""’tis""’twill""’til""’bout""’nuff""’round");
$curl str_replace($cockney$cockneyreplace$curl);

We may have a smidge of a small patch of dirt to loiter on, but I'm not a cockney :P

Afwas wrote:

Your last example is about the right combination of grace and functionality, but I could live without the (\w)"(\W)
and even with .? in stead of \W? and -perhaps- even (\w)" in stead of (\w)"(\W)

--ƒ

Without sounding funny :

¥åßßå wrote:

Come up with the bullet proof answer and I'll make the changes ;)

¥

Otherwise we'll be answering support threads in the forums for years huh?

Afwas wrote:

I am fascinated by this, but you may have noticed. :lol:

--ƒ

Hell yeah, isn't that why we all do it? :D

¥

.... after yer edit
I'll have to test that when I get a moment ;)

Oct 24, 2007 19:54

or (\w)(\W)?"(\W)? to replace everything as in:
$curl = preg_replace('/(\w)(\W)?"(\W)?/', '& #8217;$1', $curl);

Oct 24, 2007 19:59

PHP

<?php
$fred '"hello world!", said "Fred". Unfortunately he\'d a problem of thinking of a sentence that involved ";" so he "went home";-p';
 
$john  preg_replace('/(\w)(\W)?"(\W)?/''$1$2[quote]$3'$fred); 
echo 'John : '.$john;
?>

Changes open quotes as well ;)

¥

Oct 24, 2007 20:26

PHP

<?php
$fred '"hello world!", said "Fred". Unfortunately he\'d a problem of thinking of a sentence that involved ";" so he "went home";-p';
 
$john  preg_replace('/("(\W?[\s\Z]))|(\w)"(\W)/''[quote]$1'$fred); 
echo 'John : '.$john;
?>

Removes the end char of the replace when it's an alpha char?
¥

Oct 24, 2007 20:34

¥åßßå wrote:

Removes the end char of the replace when it's an alpha char?
¥

Yes

$curl = preg_replace('/"(.?[\s\Z])/', '& #8221;$1', $curl);
/* $curl = preg_replace("/'([\s.]|\Z)/", '& #8217;$1', $curl); */

John says: I don't like home";-p
Testlab says: ok

$curl = preg_replace('/"(\W?[\s\Z])/', '& #8221;$1', $curl);
/* $curl = preg_replace("/'([\s.]|\Z)/", '& #8217;$1', $curl); */

John says: I don't like home";-p and loses spaces
Testlab says: ok

$curl = preg_replace('/"[\W\s\Z]/', '& #8221;$1', $curl);
/* $curl = preg_replace("/'([\s.]|\Z)/", '& #8217;$1', $curl); */

John says: major problems
Testlab says: major problems

$curl = preg_replace('/"(\s|\Z|[\.,\?!;:\)\]}]\s|[\.,\?!;:\)\]}]\Z)/', '& #8221;$1', $curl);
/* $curl = preg_replace("/'([\s.]|\Z)/", '& #8217;$1', $curl); */

John says: I don't like home";-p and loses spaces
Testlab says: ok

Oct 27, 2007 18:50

Sorry Afwas, I got distracted with torching yet another servers cpu, where are we up to so far with the best answer?

¥


Form is loading...

powered by b2evolution – This forum is powered by b2evolution CMS, a complete engine for your website.