Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:12:58+00:00 2026-06-01T21:12:58+00:00

I have a script (pasted below) that pulls in the meta descriptions from a

  • 0

I have a script (pasted below) that pulls in the meta descriptions from a list of UrLS, I then have an export function that will export that data to CSV format.

The only problem is my export function stops when there is a character outside the UTF-8 set for example control characters like –

What is the best way to either remove these characters or replace them so they are friendly? And also how would I put this into my script?

<?php
error_reporting(E_ALL);
//ini_set( "display_errors", 0);
function parseUrl($url){
    //Trim whitespace of the url to ensure proper checking.
    $url = trim($url);
    //Check if a protocol is specified at the beginning of the url. If it's not,   prepend 'http://'.
    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
            $url = "http://" . $url;
    }
    //Check if '/' is present at the end of the url. If not, append '/'.
    if (substr($url, -1)!=="/"){
            $url .= "/";
    }
    //Return the processed url.
    return $url;
}
//If the form was submitted
if(isset($_GET['siteurl'])){
    //Put every new line as a new entry in the array
    $urls = explode("\n",trim($_GET["siteurl"]));
    //Iterate through urls
    foreach ($urls as $url) {
            //Parse the url to add 'http://' at the beginning or '/' at the end if not   already there, to avoid errors with the get_meta_tags function
            $url = parseUrl($url);
            //Get the meta data for each url
            $tags = get_meta_tags($url);
            //Check to see if the description tag was present and adjust output    accordingly
            $tags = NULL;
$tags = get_meta_tags($url);
if($tags)
echo "<tr><td>Description($url)</td><td>" .$tags['description']. "</td></tr>";
else 
echo "<tr><td>Description($url)</td><td>No Meta Description</td></tr>";
    }
}
?>

The export code:

// ExportHTMLTable

function ExportHTMLTable(tableId)
{
    this.data=[];
    this.table='';
    this.tableId=tableId;

    this.formId='exportForm';

    this.configuration={url:'../export.php',dataType:'json'};

    this.blockSend=0;
    this.blockSize=100024;

    this.requestNumber=0;

    this.rowLastIndex=0;
    this.cellLastIndex=0;

    this.format='';

    // Export
    this.exportDocument=function() 
    {
        this.reset();
        if(!this.prepareData()) return(false);

        this.send();
    }       

    // Export to CSV
    this.exportToCSV=function() 
    {
        this.format='csv';
        this.exportDocument();
    }

    // Export to XML
    this.exportToXML=function() 
    {
        this.format='xml';
        this.exportDocument();
    }

    // Reset variables
    this.reset=function()
    {
        this.data=[];

        this.blockSend=0;
        this.rowLastIndex=0;
        this.cellLastIndex=0;       
        this.requestNumber=0;
    }

    // Get table
    this.getTable=function()
    {
        this.table=$('#'+this.tableId);
        if(this.table.length!=1) return(false);

        return(true);
    }

    // Get data length
    this.getDataLength=function()
    {
        var sum=0;
        for(var rows in this.data) 
            sum+=this.data[rows].length;

        return(sum);
    }

    // Remove form
    this.removeForm=function()
    {
        var form=$('#'+this.formId);
        if(form.length==1) form.remove();
    }

    // Create field
    this.createField=function(name,value)
    {
        var field=document.createElement('input');

        field.name=name;
        field.value=value;
        field.type='hidden';

        return($(field));
    }

    // Prepare (extract from HTML table) data
    this.prepareData=function()
    {
        if(!this.getTable()) return(false);

        var self=this;
        var r=0,c=0,tr=0,tc=0,length=0;

        // Processing rows
        this.table.children('tbody').children('tr').each(function()
        {
            c=0;
            if(!$.isArray(self.data[r])) self.data[r]=[];

            // Processing cells
            $(this).children('th,td').each(function()
            {       
                length=$(this).attr('colspan')+self.data[r].length;

                for(tc=0;tc<length;tc++)
                {
                    if(self.data[r][tc]) continue;
                    self.data[r][tc]=$(this).text();    
                }

                length=r+$(this).attr('rowspan');
                for(tr=r+1;tr<length;tr++) 
                {
                    if(!$.isArray(self.data[tr])) self.data[tr]=[];
                    self.data[tr][c]=$(this).text();
                }

                c++;
            });

            r++;
        }); 

        return(true);           
    }

    // Send data
    this.send=function()
    {
        var i=0,j=0;

        this.requestNumber++;

        this.removeForm();

        var rowsNumber=this.data.length;
        var form=$(document.createElement('form'));

        form.attr('method','post');
        form.attr('action',this.configuration.url);

        for(i=this.rowLastIndex;i<rowsNumber;i++)
        {   
            var cellsNumber=this.data[i].length;
            for(j=this.cellLastIndex;j<cellsNumber;j++)
            {   
                this.blockSend++;

                var field=this.createField('exportTable['+i+']['+j+']',this.data[i][j]);

                form.append(field);

                if(this.blockSend>=(this.requestNumber*this.blockSize)) break;
            }

            if(this.blockSend>=(this.requestNumber*this.blockSize))   break;
            this.cellLastIndex=0;
        }  

        this.rowLastIndex=i;
        this.cellLastIndex=j==0 ? 0 : j+1;

        form.appendTo('body');

        if(this.requestNumber==1)
            form.append(this.createField('requestFirst',1));

        if(this.blockSend==this.getDataLength()) 
        {       
            form.append(this.createField('requestLast',1));
            form.append(this.createField('format',this.format));
            form.submit().remove();
        }
        else   $.post(this.configuration.url,form.serialize(),$.delegate(this.send,this),'json'); 
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:12:59+00:00Added an answer on June 1, 2026 at 9:12 pm

    My goodness, there’s a lot of stuff wrong with your posting..

    First: – is not considered a control character. It appears in UTF-8, latin1 and even ASCII.

    If there are indeed bytes in your string that are not valid UTF-8, then you must be dealing with some other encoding. It is the most likely that this is latin1, in which case you could use utf8_encode to convert the string.

    Don’t blindly do this though, first figure out where your data comes from and if it’s really latin1. Sometimes utf8_encode is kind of applied as a band-aid for anything behaves weird, but that’s not a good way to deal with things. As a rule, it might help to think about it this way:

    • Within your application, ensure that every string is always passed around as UTF-8.
    • If you’re receiving data from external sources, figure out what character set they use, and convert if needed.

    I have no idea how this relates to the code snippet you posted though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an R script that pulls data from a MySQL database, processes it,
I have a script that will convert a text file into a resource file,
I have a php script that will an catch email passed to it and
I have the current script included below that goes into a file with extension
I have a script called jobrunner.py that calls class methods in main.py. See below...
I have created a function (see below) that calculates a 7.5% sales tax. Now
I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then
I have some script in my default page that redirects users to language specific
I have a script that checks something on my PC every 5 minutes and
I have a script that connects to SQL Server 2005 default instance. But I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.