Solved

replace string with anything

Posted on 2009-03-29
3
188 Views
Last Modified: 2012-05-06
Hi EE
I have into array some key "00001" etc... as in code

I need to replace the string from "00001" to "1"

I use
str_replace('0', '', $myarra[riga]);

my problem is:
if value is from 00001 to 00009 is ok
if value is from 00011 to 00019 is ok
but if is 00010 return me 1 and not 10

any solution?
Best Regards
Denis
 
Array

        (

            [struttura] => Array

                (

                    [glass1] => 4

                    [glass2] => 24

                )
 

            [riga] => 00001

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 690.0

            [dimY] => 1015.0

            [can1] => 16

            [uValue] => U=1,4 W/mqýK

            [note] => N:41                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [1] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 4

                    [glass2] => 24

                )
 

            [riga] => 00002

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 1

            [dimX] => 510.0

            [dimY] => 865.0

            [can1] => 16

            [uValue] => U=1,4 W/mqýK

            [note] => N:45                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [2] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00003

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 6

            [dimX] => 498.0

            [dimY] => 1956.0

            [can1] => 12

            [uValue] => U=1,6 W/mqýK

            [note] => N:42                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [3] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00004

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 431.0

            [dimY] => 1856.0

            [can1] => 12

            [uValue] => U=1,6 W/mqýK

            [note] => N:43                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [4] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00005

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 498.0

            [dimY] => 1856.0

            [can1] => 12

            [uValue] => U=1,6 W/mqýK

            [note] => N:44                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [5] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00006

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 476.0

            [dimY] => 2151.0

            [can1] => 212

            [uValue] => U=1,6 W/mqýK

            [note] => N:46                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [6] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00007

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 1

            [dimX] => 600.0

            [dimY] => 2136.0

            [can1] => 212

            [uValue] => U=1,6 W/mqýK

            [note] => N:47                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [7] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00008

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 381.0

            [dimY] => 2151.0

            [can1] => 212

            [uValue] => U=1,6 W/mqýK

            [note] => N:49                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [8] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00009

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 1

            [dimX] => 600.0

            [dimY] => 2151.0

            [can1] => 212

            [uValue] => U=1,6 W/mqýK

            [note] => N:50                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )
 

    [9] => Array

        (

            [struttura] => Array

                (

                    [glass1] => 10331

                    [glass2] => 20331

                )
 

            [riga] => 00010

            [cliente] => FENEXTRA SRL

            [ordcliente] => 001467

            [sim] => Y

            [qty] => 2

            [dimX] => 473.0

            [dimY] => 2141.0

            [can1] => 212

            [uValue] => U=1,6 W/mqýK

            [note] => N:52                          F0079270309

            [can2] => 

            [tipologia] => doppio

        )

Open in new window

0
Comment
Question by:denny3d
3 Comments
 

Expert Comment

by:toodfa
ID: 24013247
You can use something like this :

<?php

$array =array('00001','00002','00003','00010','00011','00100','00101');
 

$result = array();
 

foreach($array as $element)

{

	$result[] = ltrim($element,'0');

}
 

echo '<pre>';

print_r($result);

echo '</pre>';
 

?>

Open in new window

0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 24013276
Hi Denis,

Greetings!

You could actually simply use php function number_format.  Just give it a try and it will really help you

Goodluck.


Regards,

eNTRANCE2002 :-)
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24013525
Run this and see what you will get using number_format()
<?php // RAY_temp_denny3d.php

error_reporting(E_ALL);
 

// TEST DATA

$vars = array('00001', '00002', '00010', 170, 234.77, '0100.001');
 

// SHOW THE EFFECTS OF NUMBER FORMATTING

foreach ($vars as $var)

{
 

// CAST AS AN INTEGER

   $num = (int)$var;
 

// CAST AS A STRING VALUE OF THE INTEGER

   $str = number_format($num);
 

// SHOW THE COMPARISON

   echo "<br/>$var = $num \n";

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP_POST() error message 9 41
Is this error or Notice in php error log? 6 32
Mysql sync between 3-4 mysql db 4 24
How to set a countdown by not using the PC time in PHP 36 43
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now