Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
PHP Help
I would like to write a simple plugin to turn the first <td>
of all <table>
tags in an html page into a <th>
. I could manage this pretty easily with Javascript DOM – but I would prefer to do it in PHP for accessibility reasons. The plugin part is pretty easy, what I am having trouble with is the string/replace stuff – is there no simple/elegant way to do something like this in PHP?
Travel Atlas * Org | Start Somewhere
Offline
Re: PHP Help
I found this badboy:
<code>
$pattern = ‘/(<(?:[<>]+(?:”[”]*”|\’[^\’]*\’)?)+>)/’;
$html_array = preg_split($pattern, trim($buffer), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
</code>
Traversing an array isn’t as easy as DOM, but it’s not too hard now either…
Travel Atlas * Org | Start Somewhere
Offline
#3 2006-05-25 08:11:30
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: PHP Help
In an HTML page, as in, a file not parsed by PHP?
Offline
Re: PHP Help
Mary wrote:
In an HTML page, as in, a file not parsed by PHP?
What do you mean? I am using ob_start
and parsing the buffer. The problem was finding tables, rows and cells in a failsafe way…
Travel Atlas * Org | Start Somewhere
Offline