Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function parse_code($data)
- {
- $data = stripslashes($data);
- preg_match_all('@\[code.*?\](.*?)\[/code.*?\]@ms', $data, $match);
- for ($i = 0, $i_cnt = count($match[1]); $i < $i_cnt; $i++)
- {
- $parsed_code = '<p class="code">' . str_replace(array('<', '>'), array('<', '>'), trim($match[1][$i])) . '</p>';
- $data = str_replace($match[0][$i], $parsed_code, $data);
- }
- return $data;
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- echo '<h1>Przetworzony [code]</h1>' . nl2br(parse_code($_POST['text'])) . '<br /><hr />';
- $text = stripslashes($_POST['text']);
- }
- else
- {
- $text = "
- przykładowy tekst
- [code]tekst
- asasdasd
- <b>sdfsfsdf</b>
- <u><i><a href='http://onet.pl'>onet</a></i></u>
- [/code]
- inny tekst i drugi znacznik code
- [code]nowy tekst
- <b>nie bedzie pogrubiony</b>
- [/code]
- Kolejny tekst";
- }
- ?>
- Test znacznika: [code]tekst[/code]
- <form action="" method="POST">
- <textarea name="text" cols="70" rows="20"><?php echo $text; ?></textarea><br />
- <br />
- <input type="submit" value="Test" />
- </form>
- <style>
- .code
- {
- font-family:courier;
- font-size:11px;
- padding:5px;
- background-color:#f0f0f0;
- }
- </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement