And these in turn are passed as arguments to the preg_replace function. Then on lines 15 and 16 they're assigned to a couple of arrays called patterns and replacements. Lines seven through to 13 define a series of variables that look rather like Klingon poetry. We'll scroll back up and take a look at it. So let's return to my editing program to see how the smart quotes function works. And then this challenge at the bottom here, we've got an opening single quote there, we've got the apostrophe in the middle, that's correct, and we've also got the closing right hand quote there. We've got some more opening double quotes here and then we've got an apostrophe. The opening and the closing quotes, they've been paired correctly. I'll just zoom in a little bit so we can see it more clearly. So let's load this page into a browser to see the result. But if I scroll down to the bottom we can see here that in the HTML on line 30 I'm passing that string to the smart quotes function and then outputting it. I'll come back to how it works in a moment. And on line six I define a function called smart quotes which takes a single argument, the text where you want to convert the straight quotes into curly quotes. We've got some straight quotes surrounding the title of the play, but in the middle there's an apostrophe. And then at the end of the sentence we've got a particular challenge. But some of the straight quotes are apostrophes like this one here. The string at the top of the script contains a combination of double and single straight quotes. In other words, converting straight quotes in texts to curly quotes. This week's technique is something that should appear to typographers, smart quotes and apostrophes. Hi, I'm David Powers, and welcome to this week's edition of PHP Tips, Tricks, and Techniques designed to help you become a smarter, more productive PHP developer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |