Rectangle 27 1

$row = 1;
if (($handle = fopen("tn-tiger-july-1.csv", "r")) !== FALSE) {
    $htmlval = "<table class='table-div' align='center' border='1' cellpadding='3' cellspacing='0'>";
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $htmlval = $htmlval."<tr>";
        $num = count($data);        
        for ($c=0; $c < $num; $c++) {
            if($data[$c] != "" || trim($data[$c]) != " "){
                $htmlval = $htmlval. "<td class='cols' align='center'>".$data[$c]."</td>";
                $htmlval = $htmlval. "<td class='cols'>&nbsp;</td>";
        $htmlval = $htmlval."</tr>";
    $htmlval = $htmlval."</table>";

In the above code variable $htmlval will contain data from CSV into HTML table format. Hope this will help you :)

HTML / PHP : Convert string of text to table - Stack Overflow

php html html-table import-from-csv
Rectangle 27 21

What you're probably running into is the actual height of lines of text. Internally, TCPDF uses the cell height ratio to control the rendered line height. When you have a TD with a single line of text, the smallest you can make it is the line's total height. So the minimum size of a td cell is fontsize * cellheightratio + any cellpadding proscribed

cellpadding can come from the cellpadding attribute, so I set it to 0 for this example. I believe at least some of the padding dimensions can also be set with setCellPaddings before writing the HTML.

You can set the cell height ratio by using a line-height CSS declaration to make rows smaller. (You can also, of course, just reduce the font size as well.)


//For demonstration purposes, set line-height to be double the font size.
//You probably DON'T want to include this line unless you need really spaced
//out lines.

//Note that TCPDF will display whitespace from the beginning and ending
//of TD cells, at least as of version 5.9.206, so I removed it.
$html = <<<EOD
<table style="border:1px solid black;" border="1" cellpadding="0">
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  <tr style="line-height: 100%;">
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 2</td>
  <tr style="line-height: 80%;">
    <td>Row 3, Cell 1</td>
    <td>Row 3, Cell 2</td>
  <tr style="line-height: 50%;">
    <td>Row 4, Cell 1</td>
    <td>Row 4, Cell 2</td>

$this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

The above code on my 5.9.206 installation produces this:

This works out to row 1 being big, twice the font size. Row 2 sets the line-height to be 100% of the font size. Row 3 is 80%. Row 4 there is 50%.

This is correct. And it applies to empty table cells as well.

I ran into this as well except I was not using HTML cells, just the standard Cell method. I needed an exact height to get page breaking borders to work correctly and I spent hours scratching my head not knowing FontSize was changing my sizes, throwing off the breaks. Saving my original font size, then calling SetFontSize(0) before writing the Cell with a Ln(), then resetting font size back fixed it. Thanks for this!

php - TCPDF - Is there a way to adjust single table row height? - Stac...

php html css tcpdf
Rectangle 27 6

 * Load HTMLPurifier with HTML5, TinyMCE, YouTube, Video support.
 * Copyright 2014 Alex Kennberg (
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

require_once(LIB_DIR . 'third-party/htmlpurifier/');

function load_htmlpurifier($allowed) {
  $config = HTMLPurifier_Config::createDefault();
  $config->set('HTML.Doctype', 'HTML 4.01 Transitional');
  $config->set('CSS.AllowTricky', true);
  $config->set('Cache.SerializerPath', '/tmp');

  // Allow iframes from:
  // o
  // o
  $config->set('HTML.SafeIframe', true);
  $config->set('URI.SafeIframeRegexp', '%^(http:|https:)?//(|');

  $config->set('HTML.Allowed', implode(',', $allowed));

  // Set some HTML5 properties
  $config->set('HTML.DefinitionID', 'html5-definitions'); // unqiue id
  $config->set('HTML.DefinitionRev', 1);

  if ($def = $config->maybeGetRawHTMLDefinition()) {
    $def->addElement('section', 'Block', 'Flow', 'Common');
    $def->addElement('nav',     'Block', 'Flow', 'Common');
    $def->addElement('article', 'Block', 'Flow', 'Common');
    $def->addElement('aside',   'Block', 'Flow', 'Common');
    $def->addElement('header',  'Block', 'Flow', 'Common');
    $def->addElement('footer',  'Block', 'Flow', 'Common');

    // Content model actually excludes several tags, not modelled here
    $def->addElement('address', 'Block', 'Flow', 'Common');
    $def->addElement('hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common');

    $def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
    $def->addElement('figcaption', 'Inline', 'Flow', 'Common');

    $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
      'src' => 'URI',
      'type' => 'Text',
      'width' => 'Length',
      'height' => 'Length',
      'poster' => 'URI',
      'preload' => 'Enum#auto,metadata,none',
      'controls' => 'Bool',
    $def->addElement('source', 'Block', 'Flow', 'Common', array(
      'src' => 'URI',
      'type' => 'Text',

    $def->addElement('s',    'Inline', 'Inline', 'Common');
    $def->addElement('var',  'Inline', 'Inline', 'Common');
    $def->addElement('sub',  'Inline', 'Inline', 'Common');
    $def->addElement('sup',  'Inline', 'Inline', 'Common');
    $def->addElement('mark', 'Inline', 'Inline', 'Common');
    $def->addElement('wbr',  'Inline', 'Empty', 'Core');

    $def->addElement('ins', 'Block', 'Flow', 'Common', array('cite' => 'URI', 'datetime' => 'CDATA'));
    $def->addElement('del', 'Block', 'Flow', 'Common', array('cite' => 'URI', 'datetime' => 'CDATA'));

    // TinyMCE
    $def->addAttribute('img', 'data-mce-src', 'Text');
    $def->addAttribute('img', 'data-mce-json', 'Text');

    // Others
    $def->addAttribute('iframe', 'allowfullscreen', 'Bool');
    $def->addAttribute('table', 'height', 'Text');
    $def->addAttribute('td', 'border', 'Text');
    $def->addAttribute('th', 'border', 'Text');
    $def->addAttribute('tr', 'width', 'Text');
    $def->addAttribute('tr', 'height', 'Text');
    $def->addAttribute('tr', 'border', 'Text');

  return new HTMLPurifier($config);

Nice find. You might want to excerpt the relevant sections however, with basic attribution. Links are regularily becoming inaccessible (in particular for github; which there's rarely an internet archive cache of). -- It registers the basic tags at least; however lacks many new attributes, just lists a few elected data-* props for example.

Noted, and full listing is now included in the post.

Cool script. HTML Purifier still seems to remove (alternative) text content in the <video> tag, althoug the configuration tells not to do so ("Flow"). Any ideas, why?

php - HTML filter that is HTML5 compliant - Stack Overflow

php html5 htmlpurifier
Rectangle 27 2

  • Add a "PreviewCutoffIndex" or similar to the articles table.
  • On page load, display the article HTML / content up to the cutoff index.
  • For the "read more" button, put the article identifier into an attribute
  • Add a click handler that makes an Ajax call, to load the rest of the article

Markup would look something like this ("data-article-id" comes from PHP on the page load):

    <?php echo $mysqlResult["articleContent"]; ?>
<a id="moreButton" data-article-id="<?php echo $articleId; ?>" href='#'>Read More</div>
<div id="moreContent"></div>
$("#moreButton").on("click", function(e) {
    var articleId = $(this).attr("data-article-id");

    // load article into "moreContent" div
    $("#moreContent").load("content.php?articleId=" + articleId);

Then the PHP content.php should return text (or more likely markup) for the remainder of the article, based on $_GET("articleId").

I think i understand most of this but how would i write up the PHP file as this is the area im struggling with the most.. would i have 1 php file named 'content.php' then inside this file each article assigned a articleID (if so how do i do this) or is it simple a different php file per article?

@box 1 file named content.php -- use a query string parameter to specify the specific articleId, which you use to retrieve the article from the MySQL table.

select article_content from articles where articleid = %articleId

You're just writing a .php file that pulls the relevant text from the database and echoes it. It is only one file that will handle every article.

Understood, thanks for the all the help guys

php - AJAX Show/hide content - Stack Overflow

php javascript html ajax
Rectangle 27 60

Something that you can try is keeping a list of the IP addresses you want to block in a text file or convert it to a dbm hash file, then use mod_rewrite's RewriteMap. You'd have to set this up in your server/vhost config. You cannot initialize a map in an htaccess file.

RewriteEngine On
RewriteMap deny_ips txt:/path/to/deny_ips.txt

RewriteCond ${deny_ips:%{REMOTE_ADDR}|0} !=0
RewriteRule ^ - [L,F] 1 1

Essentially, an IP that you want to deny and a space then a "1". Any IP in this text file will cause the server to return a 403 Forbidden. To speed things up a bit you can use the httxt2dbm to generate a dbm hash and then you'd define the mapping as so:

RewriteMap deny_ips dbm:/path/to/deny_ips.dbm

I'm not sure what the performance hit is for using mod_rewrite like this with a lot of IPs, but a quick benchmark test on apache 2.2 running on a 3Ghz i686 under linux, the difference between 5 IPs in the list versus 102418 is negligible. According to ab's output, they're nearly identical.

Is it possible for htaccess to get the list from database (Redis,Crunchbase,Mongo, MySQL or even Sqlite) ... any

Using a rewrite map, you can use the "prg" map type to run an external program for a mapping type. You can then write a perl, php, etc. script to talk to a database in order to look up an IP address. Also note that caveats listed under "Caution". You'd then use this map like you would any other map (RewriteCond ${deny_ips:%{REMOTE_ADDR}|0} !=0). This would essentially create a bottleneck for all requests. Not the best solution for talking to a database.

In apache 2.4 though, there is a dbd/fastdbd map type, which allows you to create queries through mod_dbd. This is a much better option and the mod_dbd module manages connections to the database, pools connections, etc. So the map definition would look something like:

RewriteMap deny_ips "fastdbd:SELECT active FROM deny_ips WHERE source = %s"

Assuming you have a table "deny_ips" with 2 columns "source" (the IP address) and "active" (1 for active, 0 for inactive).

Is there a visible solution to manage such kind of issue in production

If you are storing all of the blocked IPs in the database, it's a matter of managing the contents of your database table. If you are using the dbm map type, I know at least perl has a DBI for managing dbm files, so you can use that to add/remove IP entries from the deny list. I've never used it before so I can't really say much about it. Managing a flat text file is going to be a lot trickier, especially if you plan on removing entries, and not just append to it. Outside of using a database and apache 2.4's mod_dbd, I don't think any of these solutions are out of the box or production ready. It's going to require custom work.

I know the best solution is Block the IPs at the firewall level is there any way to pragmatically add/remove IP to the firewall

For IPtables, there is a perl interface that's marked as Beta, but I've never used it before. There's libiptc but according to netfilter's faq:

Is there an C/C++ API for adding/removing rules?

Now you might think 'but what about libiptc?'. As has been pointed out numerous times on the mailinglist(s), libiptc was NEVER meant to be used as a public interface. We don't guarantee a stable interface, and it is planned to remove it in the next incarnation of linux packet filtering. libiptc is way too low-layer to be used reasonably anyway.

We are well aware that there is a fundamental lack for such an API, and we are working on improving that situation. Until then, it is recommended to either use system() or open a pipe into stdin of iptables-restore. The latter will give you a way better performance.

So I don't know how viable a libiptc solution is if there's no API stability.

+nice one ... never used htaccess with file .. .. any performance issues ?

@Baba The map needs to be defined in the vhost/server config, will cause error in htaccess. The rule itself can be placed in an htaccess file though, and obviously, it's a bit slower than in vhost/server config, but the file is short (doesn't contain the 100K IPs), so there shouldn't be any additional performance issues.

@JonLin, yup the rule could be moved to a .htaccess file, but as you point out the map needs to be defined in the vhost/server config, so what's the point of the performance hit of moving the rule into an .htaccess file?

php - How to Block 100,000+ Individual IP addresses - Stack Overflow

php apache security .htaccess
Rectangle 27 1

<!DOCTYPE html>
<html lang="">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table Check</title>


    <tr class="row">
      <td class="col id"><input class="txtdata" name="id" value="1"></td>
      <td class="col name"><input class="txtdata" name="name" value="Jhon"></td>
      <td class="col city"><input class="txtdata" name="city" value="NY"></td>
    <tr class="row">
      <td class="col id"><input class="txtdata" name="id" value="2"></td>
      <td class="col name"><input class="txtdata" name="name" value="Jane"></td>
      <td class="col city"><input class="txtdata" name="city" value="LA"></td>

<script type='text/javascript' src=''></script>

$(document).ready(function($) {
  $('.txtdata').on('change', function(){
    var parent = $(this).parent('.col').parent('.row');
    var id = $(parent).find('.id').find('input').val();
    var name = $(parent).find('.name').find('input').val();
    var city = $(parent).find('.city').find('input').val();
    var attribChanged = $(this).attr('name');
    data = {id: id, name: name, city: city, attribChanged: attribChanged};
    $.post('getter.php', data, function(data){
$name = $_REQUEST['name'] . '(mod)';
$id = $_REQUEST['id'] . '(mod)';
$city = $_REQUEST['city'] . '(mod)'; 
echo '<td class="id"><input class="txtdata" name="id" value="'.$id.'"></td>
      <td class="name"><input class="txtdata" name="name" value="'.$name.'"></td>
      <td class="city"><input class="txtdata" name="city" value="'.$city.'"></td>';

I tried this now...doesn't work... Read the edit I made - this is what you tought I ment?

Ok so you need to send the ID of the row to change it in the DB too, and update the table with the new name. Basically reflect in the DB any change you do to the table. is that what you want?

precisely, if I change David's city to "London" for example I want to send 3 things: 1) The ID - so I know which specific row. (in this case - "1") 2) The column name - so I can know which column has changed. (in this case - "city") 3) The data after change - so I know what to update. (in this case - "London")

Hi check the answer, I've just updated it. I think it's what you need, but you'll have to adapt it to your code. Now is sending the ID, Name and City.

You are welcome! Thanks! :)

javascript - Update mySql based specific onChange - Stack Overflow

javascript php jquery html
Rectangle 27 2

I suggest you read this thread about HTML parsing. Nowadays there are loads of XML/HTML parsers you can use.

Since the HTML code is very badly written (attribute values have no quotes, text occurs inside table but outside tr), it's hard to parse the HTML code.

$var = "<TD WIDTH=30%><B>Joining Date</B></TD></TR>STRINGTOBEMATCHED</TABLE>";
$regex = "%</TR>(.*?)</TABLE>%i";
$matches = null;
preg_match($regex, $var, $matches);

$result = $matches[1];

but I strongly recommend you to use a library denoted in the abovementioned thread.

php - how to match this text from between html tags using preg_match -...

php preg-match
Rectangle 27 1

This is wrong question asked out of wrong assumptions.

  • Asking "if php function is slower/faster" makes no sense. PHP functions aren't fast ot slow. everything depends on the content of the function.
  • Do not bug yourself with performance questions until you face the real problem.

As for the question, to store capitals in the database is the only reliable method, from the right database structure point of view.

I used States and Capitals in the example because its easier to explain for this example. The question is not about db structure, but about performance. I mean, that db table contains only several thousands of rows, does NOT grow and stays permanent.

It makes no sense performance-wise. And it doesn't matter what size db has and if it grows or not, The proper structure it must have despite of such rubbish details.

performance: html

Rectangle 27 1

Assuming that in method 1 you're not going to the database at all, but simply iterating over a hardcoded array in a PHP file, it should be faster.

for each state
   render state select item
next state

Whereas option 2 would be:

retrieve states from DB
for each record in result set
   render state select item
next record

You still have to iterate over 100 states - except you're getting them from a database result, rather than an array.

However, in practice, I doubt you'd see a huge difference; as others have mentioned, from a maintainability point of view, keeping things in the database may be a better choice.

performance: html