A
A
Arthur Koch2012-12-24 06:33:58
PHP
Arthur Koch, 2012-12-24 06:33:58

Tell me the principle of writing a code converter

Incoming data:

<wrap width="600" align="center" clear>
<col>
<row>text</row>
<row>text 2</row>
<row><img width="200" height="100" clear></row>
</col>
<separator height="20">
</wrap>


Need to get:

<table width="600" align="center" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>text</td>
<td>text 2</td>
<td><img width="200" height="100" style="display:block; border:0;"></td>
</tr>
<tr>
<td height="20"></td>
</tr>
</table>


This is just a simple example of code processing. There are actually many more combinations of replacements.
How is it more convenient to store replacement combinations and use them (regulars?) in practice in the future?

I will give an explanation about the code above:

- wrap is replaced with a table for which zero collapse
is specified - the wrap tag's clear parameter resets cellpadding and cellspacing for this table
- col is replaced with tr
- row with td respectively
- the img tag's clear parameter resets the border and sets the display: block for image
- separator adds an empty string with the given height

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lacki, 2012-12-24
@lacki

I think the answer to your question is XSLT .

D
dVaffection, 2012-12-24
@dVaffection

In fact, if you can replace one occurrence in a string with another, it's better to pull the data out of the (x)html structure and store it separately. You can then display them in any view. How to pull? As suggested above XSLT, if you are more familiar with selector syntax you can use a library like symfony/CssSelector

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question