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
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">

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.