Dividing a String into parts [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you can adjust the code in the file, just have it set a variable, otherwise, use ob_start().
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

OK well I am getting the contents of the page by using:

Code: Select all

// start CURL
$ch = curl_init(); 
// SET URL
curl_setopt($ch, CURLOPT_URL, 'http://site.com/'); 
// Username and password, separated by a colon. 
curl_setopt($ch, CURLOPT_USERPWD, 'username:password'); 
// Turns curl into a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set to string
$str = curl_exec($ch); 
// close CURL
curl_close($ch);
But when I do

Code: Select all

$numbers = explode(' - ', $str, -1);
I only get 4 numbers instead of the 5 numbers I get on the page included. Is it because they are in the format of X - X - X - X - X... or what?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you've told explode to return all but the last 1.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

well how could I do it so it does every number without setting it to 5 cause I wanting it to do it for what ever amount it sends so it would do X - X or X - X - X - X - X - X - X - X
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Ah, I think I got something is it just you need to put a max number in so that say I won't have more than 100 X's just put in 100 in the spot?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

don't send the last argument to it.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

ok, thanks feyd. :)
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Ok, Now I have another question. Sometime is there is a special something that goes with the numbers it prints out

Code: Select all

X - X - X - X  <br> Other: X 
How could I extract that from the variable $str and put it into $number[special] and remove the <br>
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

I figured it out.. Thanks everyone :)
Post Reply