Jump to content

combining client-side code with mySQL


bcatt

Recommended Posts

I'm wondering if it's possible to store code as table data. Preferably XSL or CSS code.

 

Example cell data:

<format1>I want this text to be rendered to the user as blue, italic, 14pt Arial</format1>
<format2>And this text will be rendered to the user as orange, bold, 12pt Helvecta</format2>

So that if I use php to pull this entry from the database to display on the page, my client-side css or xsl can then format these items based on their enclosing tags. Someone told me that if I don't do it right I will mess things up. I'm using SQL-front to manage my database, and using V5.0 of mySQL (within V2.0 of easy php).

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/106562-combining-client-side-code-with-mysql/
Share on other sites

your looking at something similar to BBCode but I think what you want to do is use php more along the limes

i.e you input those rows into mysql

<format1>This text</format1>
<format2>More Text</format2>

and then you use a php function to do a replace to replace <format1> with <span class="format1">

Oh, thanks. I'm completely new to SQL/PHP (on my second day of figuring it out), so I haven't learned all of what I can do with them yet.

 

So, just to make sure I'm understanding properly, having html-like tags in mySQL table cells isn't going to cause any problems with my database? And I can easily manipulate these "markers" once the data has been pulled?

take this

<?php
function bb2html($text){
  $bbcode = array("<", ">",
                "[list]", "[*]", "[/list]", 
                "[img=", "]", 
                "[b]", "[/b]", 
                "[u]", "[/u]", 
                "[i]", "[/i]",
                '[color="', "[/color]",
                "[size=\"", "[/size]",
                '[url="', "[/url]",
                "[mail=\"", "[/mail]",
                "[quote]", "[/quote]",
                '"]');
  $htmlcode = array("<", ">",
                "<ul>", "<li>", "</ul>", 
                "<img src=\"", "\">", 
                "<b>", "</b>", 
                "<u>", "</u>", 
                "<i>", "</i>",
                "<span style=\"color:", "</span>",
                "<span style=\"font-size:", "</span>",
                '<a href="', "</a>",
                "<a href=\"mailto:", "</a>",
                "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>",
                '">');
  $newtext = str_replace($bbcode, $htmlcode, $text);
  //$newtext = nl2br($newtext);//second pass
  return $newtext;
}
?>

and replace the tags with a bunch of <span class="formatX"> </span>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.