Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » PHP Help

#1 2006-05-25 00:20:44

rloaderro
Archived Plugin Author
From: Costa Rica
Registered: 2006-01-05
Posts: 190
Website

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

#2 2006-05-25 01:36:31

rloaderro
Archived Plugin Author
From: Costa Rica
Registered: 2006-01-05
Posts: 190
Website

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

#4 2006-05-25 15:18:29

rloaderro
Archived Plugin Author
From: Costa Rica
Registered: 2006-01-05
Posts: 190
Website

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

  1. Index
  2. » Archives
  3. » PHP Help

Board footer

Powered by FluxBB