Wrapping a text using php, based on language - php

My problem is that I have quite a small area (div or span), in which one to about five words are displayed. However, the area is too small for some words (for instance "muziekgeschiedenis" will surpass the area's bounds). Is there a way in PHP to wrap this word, but not solely based on number of characters? I can use wordwrap(), or just CSS properties for wordwrapping, but that may wrap this word into "muziekgeschiedeni-s", which is not wanted. It should break into for instance "muziekgeschiede-nis", based on syllables. Are there any PHP extensions that support word breaking/wrapping like this?
Thanks!

this is called "hyphenation" and this is the first link that google gives on "php hyphenation"
http://yellowgreen.de/phphyphenator
hope this helps

Here is a PHP based hyphenation library, and a port of this library to a WordPress plugin: wp-Typography.

For PHP there is this PEAR Package TexHyphen, which uses the Tex algorithm to find syllables. It is alpha for six years and not maintained though, so user187291's suggestion is probably a better bet.
An alternative to PHP would be Javascript. There is a Hyphenator lib at Google Code. Keep in mind that this approach requires the user to have JavaScript enabled though. Actually, phpHyphenator is a port of this lib.

There is also this port of the TeX-Hyphenation Algorithm.

Related

PHP str_replace into microsoft word template

Right now I'm get task to make generate contract letter function in HRMS.
I'm already using CKEditor but the result is very different since the purpose made CKEditor is not like Microsoft Word or Google Docs purpose.
So I'm having idea that I'm making the template first in Microsoft Word and use PHP function str_replace to passing the data into Microsoft Word template.
The question is :
1. With that flow, is it possible to do that?
2. If Question 1 is possible can you hit me with the sample?
Many Thanks,
Hendra
There are several Classes that can do at least part of what you are trying to do:
wrklst/docxmustache
openTBS – Tiny But Strong
PHPWord
docxtemplater pro (basic opensource / free version / MIT license available as of writing; image replacing is a commercial plugin)
docxpresso (commercial)
phpdocx (commercial)
The first 4 of these are at least partially open source and investigating the code will help you understand the process, which is not trivial with word. In addition you can check out http://officeopenxml.com for the format details.
The main problem I see is with proper HTML to openXML conversion. Meaning to convert the styling from CKEditor (which might be HTML) into the proper XML Styling, which functions quite differently and a direct translation is not trivial. Check out https://github.com/wrklst/docxmustache/blob/master/src/WrkLst/DocxMustache/HtmlConversion.php so see some basic HTML conversion on singular runs of bold, italic and underlined text.
To my knowledge there is no maintained open source package that delivers proper html to openxml conversion. If you need this and cannot write it yourself, you will probably go for one of the paid solutions.
Good luck.
Docx is a zipped format that contains some xml. If you want to build a simple replace {tag} by value system, it can already become complicated, because the {tag} is internally separated into <w:t>{</w:t><w:t>tag</w:t><w:t>}</w:t>. If you want to embed loops to iterate over an array, it becomes a real hassle.
source : https://docxtemplater.readthedocs.io/en/latest/goals.html
You could use the library I created in answer for this problem : https://github.com/open-xml-templating/docxtemplater , it works with JS in the browser or with node.js.

Generate keywords for contents through Solr

I'm integrating Solr for my new PHP application.
As I'm newbie in solr section, I want to know that is it possible to generate some useful tags for every content pages through solr? something like auto-tagging mechanism.
Thanks in Advance...
P.S My contents available in both Persian and English languages.
something like auto-tagging mechanism.
Yes, you can build something like that.
There are 2 different ways to realize that:
Use the Clustering Component from Solr to build groups of docs and label those docs by solr. The labels are something like the taggs your are looking for.
Realize a tagging by using the MLT feature.
I started an auto-tagging project with the 1.) method with medium success. Finding labels for a cluster of documents is an hard process.
But fortunately, I had some already taggegd documents. If you also have some documents with valid tags, than you can use the 2.) method to use those document as an base to start learning:
Take a document without tags and perform a MLT search against docs with tags. Take the tags from the docs you fond and count them. Depending on the count, apply one or more tags to the untaggegd document. In my case, that works very well. Method 2.) is an cheep implementation of machine based learning, but you will get 95% success with only 5% Work-input.
As it's a PHP application, if it's OK for you to generate tags in php and then inserting/updating to Solr, Here are few options -
If using a web service is OK, check Yahoo's Term Extractor
If you can/want to host a term extraction service yourself to (may be in local server), check FiveFilters
Here is a php function for extracting valuable words from text block. Surely not as efficient as Yahoo Term Extractor, but it may work for you.

Wrap functions automatically in PHP Designer 8

As I start to work in OOP's, I build a lot of classes and functions and I'd love to wrap each function automatically and expand when I like.
Is that possible with PHP Designer 8. I am a jEdit user, does PHP Designer supports it?
The answer to your question in the title is CTRL+R.
The answer to your question is NO... PHPDesigner does not support selective wrapping of code till atleast version 8.1...
This sheet would provide you feature comprision between PHP editors
https://docs.google.com/spreadsheet/ccc?key=0Agccij5yGAXacFY4WHlVU1VPTTdFVDA3cm40bjdOWUE#gid=0
What Ctrl+R gets you is wordwrap which you would get even in notepad(without ++)...

Search Algorithm for tags and contents

i'm designing a tag system and i'm looking for a good search algorithm. It must consider both tags and text contents, maybe with the possibility to give more importance to tag or to contents according to my needs. Is there anything similar in the literature? It's my first time working on such a system, so easy and popular solutions could fit too.
Thank you for your time.
It would be possible to implement this within MySQL but I think it would be worth looking at dedicated full text search applications for what you're trying to achieve. Most of them handle tags (usually referred to as attributes) as this is a common use case.
I'd recommend looking at the following:
Sphinx Search
Elastic Search
Solr

How to make a pdf file using PHP

How can I make a PDF file in PHP. What I want to make is a student list. So I want to query the database, get the information and give it to the user as a PDF when he clicks generate student list.
You have two good options first is the standard php library for manipulating pdf's: http://us2.php.net/pdf
Or you can use http://www.fpdf.org/. I would recommend the second.
Other options include:
www.pdflib.com
PEAR has the PEAR::File_PDF package.
There are are already many libraries available with PHP bindings. One that comes to mind is PDFLib (www.pdflib.com). If I am not mistaken there should even be a lite version that you can use for free. But just check it out.
Hope it helps
I use the ezPDF class. Lightweight, simple, easy to use, and handles most cases.
FPDF is a classical in the field. It seems it has limitations when handling Unicode (eg. Asian char sets), so there are libraries extending it (UFPDF, TCPDF...).

Categories