Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

searching within a parsed csv file

shadowsilshadowsil Posts: 3Member
ok here is what I want to do.
I want to be able to parse a csv file but I only want to keep lines that start with a certain character or set of characters

this is the code Im using:

$line = 0;
$maxCols = 0;

while (($line < $previewLimit) && ($data = fgetcsv($myFile, 2048, $delimiter))) {
$numOfCols = count($data);
if ($numOfCols > $maxCols) $maxCols = $numOfCols;

$csv_block .= "
";
I basically want to ignore any line with a 1 as the first character. how would I go about doing this? I know its probably a newb question but Im only a beginner hehe :) thank you

Comments

  • DarQDarQ Posts: 1,625Member
    http://php.net/strstr

    with this function you can see if X is found in string Y. if true then the X is found. so a:

    if (strstr($y,$x)) {
    // X found
    } else {
    // Y found
    }

    : ok here is what I want to do.
    : I want to be able to parse a csv file but I only want to keep lines that start with a certain character or set of characters
    :
    : this is the code Im using:
    :
    : $line = 0;
    : $maxCols = 0;
    :
    : while (($line < $previewLimit) && ($data = fgetcsv($myFile, 2048, $delimiter))) {
    : $numOfCols = count($data);
    : if ($numOfCols > $maxCols) $maxCols = $numOfCols;
    :
    : $csv_block .= "
    ";
    : I basically want to ignore any line with a 1 as the first character. how would I go about doing this? I know its probably a newb question but Im only a beginner hehe :) thank you
    :

    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    NEW url--> http://mark.space.servehttp.com

  • JonathanJonathan Posts: 2,914Member
    : http://php.net/strstr
    :
    : with this function you can see if X is found in string Y. if true then the X is found. so a:
    :
    : if (strstr($y,$x)) {
    : // X found
    : } else {
    : // Y found
    : }
    :
    I think strpos would be better.
    http://php.net/strpos

    That returns the position of one string in another, so you can see if it's at the start of the line.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • shadowsilshadowsil Posts: 3Member
    : : http://php.net/strstr
    : :
    : : with this function you can see if X is found in string Y. if true then the X is found. so a:
    : :
    : : if (strstr($y,$x)) {
    : : // X found
    : : } else {
    : : // Y found
    : : }
    : :
    : I think strpos would be better.
    : http://php.net/strpos
    :
    : That returns the position of one string in another, so you can see if it's at the start of the line.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    thanks guys I appreciate it =P that gives me an idea of how to do it.
Sign In or Register to comment.