Search code examples
phpstringparsingphpquery

Decimal number with comma or point after first number


EDIT 2

Thank you all for your help! By fusing the answers and some other forum post I managed to solve it by:

$string = strip_tags($oNode['div.item-prijs']);
$array = str_split($string,1); 
$arraytotal = ( $array[0] . ',' . $array[1] . $array[2] );
echo $arraytotal;

And shows the correct price now. "7,49" The PHP script I have automatic converts , to .

Sorry that I can't give more question answered markings. Case closed.

Come on guys

$price = strip_tags($oNode['div.item-prijs']);
$new_price = substr(chunk_split($price, 1, ','), 0, -1); 
echo $new_price;

This will echo 7,4,9 and not 7,49. But this code is the best code so far. Someone any idea how to fix this?

Well I'm stuck at this for a while now..

I am parsing data from a website, and I want to get the price but on the website there is no comma or point between the prices. so it shows like 499, the 4 is bigger than 99.

When I do:

$price = $oNode['div.item-prijs'];
echo $price;

It will echo 499. I want it to add comma or point between 4 and 99.

I've tried:

$price = $oNode['div.item-prijs'];
$new_price = substr(chunk_split($price, 1, ','), 0, -1); 
echo $new_string;

This will echo:

<,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,7,<,s,u,p,>,4,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,4,<,s,u,p,>,9,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,1,<,s,u,p,>,4,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,0,<,s,u,p,>,6,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,1,<,s,u,p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,0,<,s,u,p,>,9,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,1,<,s,u,p,>,4,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,2,<,s,u,p,>,0,8,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,1,<,s,u,p,>,4,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,3,<,s,u,p,>,4,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,6,<,s,u,p,>,1,8,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,3,<,s,u,p,>,9,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,4,<,s,u,p,>,2,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,><,d,i,v, ,c,l,a,s,s,=,",i,t,e,m,-,p,r,i,j,s,",>,<,p,>,2,<,s,u,p,>,7,9,<,/,s,u,p,>,<,/,p,>,<,/,d,i,v,>

And this:

$string = $oNode['div.item-prijs'];
    $new_string = substr(chunk_split($string, 4, ','), 0, -1); 
    echo $new_string;

This will echo:

,
7,49<,/sup,>,

<,/p><,/div,>,

4,99<,/sup,>,

1,49<,/sup,>,

0,69<,/sup,>,

1,99<,/sup,>,

1,49<,/sup,>,

1,49<,/sup,>,

3,49<,/sup,>,

3,49<,/sup,>,

3,69<,/sup,>,

1,19<,/sup,>,

1,89<,/sup,>,

1,99<,/sup,>,

1,99<,/sup,>,

1,49<,/sup,>,

2,99<,/sup,>,

1,99<,/sup,>,

1,09<,/sup,>,

2,25<,/sup,>,

1,99<,/sup,>,

0,99<,/sup,>,

1,54<,/sup,>,

2,09<,/sup,>,

1,78<,/sup,>,

1,71<,/sup,>,

0,99<,/sup,>,

1,49<,/sup,>,

2,08<,/sup,>,

1,49<,/sup,>,

3,49<,/sup,>,

6,18<,/sup,>,

3,99<,/sup,>,

4,29<,/sup,>,

2,79<,/sup,>

So it will crab every price on the page, but also echo's html code. It splits the html code instead of only the price.

Below is the HTML code on the website

<div class="item-prijs">
        <p>
            <cufon class="cufon cufon-canvas" alt="4" style="width: 27px; height: 42px; ">
                <canvas width="47" height="43" style="width: 47px; height: 43px; top: -1px; left: -2px; "></canvas>
                <cufontext>4</cufontext>
            </cufon>
            <sup>
                <cufon class="cufon cufon-canvas" alt="99" style="width: 24px; height: 20px; ">
                    <canvas width="35" height="21" style="width: 35px; height: 21px; top: -1px; left: -1px; ">
                    </canvas><cufontext>99</cufontext>
                </cufon>
            </sup>
        </p>
    </div>

What am I doing wrong? I've tried different ways, but no success. Can someone please help me out with the right code?

Thanks


Solution

  • Try this, add strip_tags it remove any HTML tags:

    $price = strip_tags($oNode['div.item-prijs']);
    $new_price = substr(chunk_split($price, 1, ','), 0, -1); 
    echo $new_string;