Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Preg_split First Item In Array Is Blank


could someone please explain to my why using the code below generates a blank item in $array[0] please. The 'x' from xbox360 is in $array[1]?




View Complete Forum Thread with Replies

Related Forum Messages:
Write A Conditional Statement To See If The Current Item In An Array Is The Last Item.
This seems like it would be so simple, but I haven't been able to solve it. I want to write a conditional statement to see if the current item in an array is the last item. I tried

if (count($array) == (current($array))

but that didn't work. count($array) will give me the number of items in the array. What do I use for the current position in the array.

View Replies !
Array_unique - How-to Get First Item Value In Repeated Array Item
I would like to know how-to get the first value of repeated items too in an array using something like array_unique. Code:

View Replies !
Multidimensional Array Syntaxt For Preg_split Array Using Submitted Textarea
I have two textarea's called textarea1 and textarea2.  What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so

$array = preg_split("/[
]?[
]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[
]?[
]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);

then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas

finishing off i wanted to create an array that would input an expression such as:

echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";

into a text area on the next page.  ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page.

For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says

"while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number"  I hope that makes sense

Any ideas? Code:

View Replies !
Use Preg_split To Break It Into Separate Array Elements
i have the following string:

$str = "HEMSKY, ALES +1 15:33 18 :51 6:31 0:05 8:57 1 1"

and i want to use preg_split to break it into separate array elements. i think the following code should work, but it doesnt PHP Code:

$str = "HEMSKY, ALES +1 15:33 18 :51 6:31 0:05 8:57 1 1"
$array = preg_split("/[,s]/", $str, 8)

View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following:

$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$basket_containers = explode('¦', $BB_Basket);
unset($basket_containers[0]);
print_r($basket_containers);

This results in

Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 )

Now when I try to explode further with

$basket_items = explode(',', $basket_containers);
print_r($basket_items);

This results in

Array ( [0] => Array )

This should result in a 6 item array. Any ideas what I'm doing wrong?

View Replies !
Item In Array
I have an array, set up like this:

$this->navigation_array['Home'] = array('text' => 'Home', 'act' => 'Home', 'redirect' => 'No', 'active' => 'Home', 'link' => 'index.php?act=home', 'default' => 'Info');
$this->navigation_array['Forums'] = array('text' => 'Forums', 'act' => 'Forums', 'redirect' => 'No', 'active' => 'Forums', 'link' => 'index.php?act=forums', 'default' => 'Info');
$this->navigation_array['Users'] = array('text' => 'Users', 'act' => 'Users', 'redirect' => 'No', 'active' => 'Users', 'link' => 'index.php?act=users');
$this->navigation_array['Config'] = array('text' => 'Configuration', 'act' => 'Config', 'redirect' => 'No', 'active' => 'Config', 'link' => 'index.php?act=config');

I want to find the first item inserted into the array, namely "Home". What is the fastest way to just call the first entry? You cant use $this->navigation_array[0] in this case because the keys are text not numbers.

View Replies !
Deleting An Array Item
I have a standard array:
$foo = array(
0 => 'abc'
1 => 'def'
2 => 'ghi');

and I have a variable, $bar, which equals 'def' ... and I want to check
my array to see if the value of $bar exists in the array, and if it
does, delete it from the array.

if (in_array($bar, $foo)) {
// what goes here???
}

I've done this before, but for the life of me, I'm drawing a blank now.
Help a bruthah out?

View Replies !
Random Item Of An Array
What is the best way of picking out a random item of an array, regarding speed and CPU-usage ? I need a super fast way of picking out an ID from my MySQL db.

View Replies !
Delete Item From Array
How do I search for an item within an array, then delete it?

View Replies !
Remove An Item From And Array Entirely
How do you remove an item from an array...

View Replies !
Remove Item From Array
I'm having some trouble understanding how to remove items from an array. The array is created like this: Code:

View Replies !
Modify Array Item
I'm building a shopping cart and need to add the function so if an item is selected twice, the 'quantity' counter increments. I can't get the syntax right for modifying the array value. I have this:

foreach ($_SESSION['basket'] as $key => $row)
{
if ( $row['gnsz']==$gnsz)
{
$newqty=$row['qty'] ;
$newqty++;
$row['qty']= $newqty;
}
}

it picks up the first qty value but I can't seem to modify it in the array. I'm making a dumb mistake somewhere .

View Replies !
Put The Itemid Of An Item Into An Array.
$count = 1;
foreach($trade as $val) {
$val = checkinput($val);
$sel=mysql_query("SELECT * FROM `inventory` WHERE `ID` = '$val' AND `userid` = '$userid2'") or die(mysql_error());
$n=mysql_num_rows($sel);
if($n == 0) {
$input = "You do not own this item.";
error($input);
}
$g=mysql_fetch_array($sel);
$itemid = $g['itemid'];
$itemid[$count] = $itemid;
$count++;

}

Basically, my script is trying to put the itemid of an item into an array. The problem i'm getting is that, it's not saving the values in the array. For example, if i have 3 items and it puts them into the array, it will only save the 3rd item in the array $itemid[3] and 1 and 2 will be blank.

View Replies !
Current Item From An Array
i have an include file with many arrays that look like this: Code:

$event[] = array ('stuff' => 'bla');
$times[] = mktime(0,0,0,6,9,2007);

as of right now, I am using asort to sort all of these by date and display them as a list.

View Replies !
Find Item In Array
I have the following array

$array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4');

how do i select the value that is provided BEFORE the key i provide

ex:
$mykey = "k2";
$array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4');
$value = somefunctions(); // gives the value v1

ex:
$mykey = "k4";
$array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4');
$value = somefunctions(); // gives the value v3.

View Replies !
How To Remove An Item From An Array
Been looking around on how to remove an item from an array, i need the item totally removing, without a gab in the array, as i will be using the implode fuction afterwards.

View Replies !
Item In A Multidimensional Array
I have a multidimensional array (I think). It is an array that has arrays inside it. The inside arrays all have the same structure, (qty, product, color, size). How do I count how many items are 'White' * qty? I looked into the php manual and found array_count_values but others say it doesn't work with MD arrays.:confused:

array(
[0] array([0]qty, [1]product, [2] color, [3] size)
[1] array([0]qty, [1]product, [2] color, [3] size)
[2] array([0]qty, [1]product, [2] color, [3] size)
[3] array([0]qty, [1]product, [2] color, [3] size)
[4] array([0]qty, [1]product, [2] color, [3] size)
[5] array([0]qty, [1]product, [2] color, [3] size)
[6] array([0]qty, [1]product, [2] color, [3] size)
...)

View Replies !
Extra Item In My Array
Why is my code.

$urlarray = explode("/", "/about/new/index.php");
print_r($urlarray);

returning this

Array ( [0] => [1] => about [2] => new [3] => index.php ).

Perhaps I am being dense but why do I have an extra empty value at the beginning of the array. Is there any way I can make it return the ones I want (ie only those containing an actual value) or do I simply have to work around this.

View Replies !
Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?

View Replies !
Shopping Cart Item Array
Trying to build a small simple shopping cart and I am having difficulty getting the solution. The cart is displaying each product, but it is overwriting the values. So if I have added 10 products, it shows ten items, but each item has the values of the last product I added.

I think that this may be due to me trying to use a key to store both an array and string at once, but Iam not sure. I have looked at other examples but due to different methods, syntax is throwing me off. Code:

View Replies !
Remove A Single Item From An Array
I have gathered an array of ID's. I need to go throught the array and find a specific ID and remove it from the array. Because we want to keep that ID. Any suggestion of how to do that.

View Replies !
Remove Item From Session Array
i have a simple script that adds an item id to a session Code:

View Replies !
Select One Row Of An Array Where Item Number Is ..?
When I call the Ebays XML API I get an array or something similar back (see the code sample), is it possible to "select item_id where item_id = 123123" or something similar as in MySQL? If, How can I do that? Also, I need to attach a PHP variables to the row I selected as for example $starttime, $endtime and so on.

Here is the code sample (the end of the scritpt);

PHP Code: ....

View Replies !
Retrieving Previous Array Item
I have an array. The array key is the id of the item (for example
categories[91], 91 is the ID of the category) all ID are not exactly in
date order, but they're added to the array in date order, how do I find
the previous (in the sense of when it was added) array entry of, for
example category[&#3991;']?

View Replies !
Arrays : Returning A Reference To An Array Item ??
I am currently storing a set of objects inside an array,

$itemlist = array();
$itemlist[] = new item("myitem");
//...

and I am looking to develop a search function, which returns a
reference to the found item.

function &search_item($itemlist,"myitem") {
//...
}

I am trying to figure out how to obtain a reference to a given item in
an array.
Indeed, foreach() and each() seem to work on copies of the data in the
array.
For example:

$array = array("a","b","c","d");
print_r($array);
foreach($array as $v) $v="xxx";
print_r($array); // $array is unchanged

reset($array) ; while(list(,$v)=each($array)) $v="xxx";
print_r($array); // $array is unchanged, again

View Replies !
Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this:

$people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo');

...to this...

$people = array('Tom', 'Dick', 'Brenda', 'Jo');

The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove.

function removeItem ( $item ) {
   $len = count ( $_SESSION['basket_arr'] ) ;
   if ( $len == 1 ) {
      emptyBasket ( ) ;
   } else {
      for ( $i = 0 ; $i < $len ; $i++ ) {
         if ( $item->id == $_SESSION['basket_arr'][$i]->id ) {
            //$_SESSION['basket_arr'][$i] must go
         } } }}


View Replies !
Removing Item From Array Then Overwriting File
I have a bookings.txt file which has a list of dates each on a new line, for example: -

21/06/07
22/06/07
29/06/07
25/12/07
01/01/08

I also have a variable $event_dd_mm_yy which I want to remove from this file if found. Code:

View Replies !
Checking For A Blank Array
My project validates a user's registration form by going through a series of methods.

Each step of the process adds another item to an array called errorLog. If a step is successful, its corresponding item will be empty or blank. If something went awry, a string of text describing the problem will be inserted into the array.

Is there an easy way to determine whether every single item in the errorLog array is empty/blank, indicating that no errors occurred, allowing the site to process the registration?

View Replies !
Deleting Blank Entries From Array?
The resulting arrays that i get from my select statements always seem to have some blank entries, in addition to the correct ones. It is rather odd, is there any way i can scan through it and delete these blank entries? Here is the print_r of the arrays. PHP Code:

View Replies !
How To Use An Array To Make It Stop At A Blank Space
I have Description. Description is passed though a $POST. Description would contain for example 12.23 4. All i want is the last number. So in this case 4. Im not sure how to use an array to make it stop at a blank space or just read the last number (whether the number is 4 or 400) Im trying something like below Code:

if (description!="")
{
var arrDescription = description.split(separator);

for (var z = 0; z < description.length; z++)
{
if (arrDescription=" ")
{
newdescription=description;
}

View Replies !
Preg_split And XML
I need help to parse the content of an XML file so that I can store all the data fields into a database.

The structure of the XML is something like this: ....

View Replies !
Preg_split
lets say I have a line of text with multiple spaces between each word..
I am not sure how many spaces. I would like to take the line of text,
and change it to put only one space between the words. Code:

View Replies !
Preg_split Question
Let's say I have a string in the format of

Quote: /(s{2}<-[s]{2})(S+|W+|)(s{2}->[s]{2})/u

I had to make it like this because otherwise, I cannot pick up the words I need in between the 2 spaces, followed by a opening bracket followed by another 2 spaces. etc etc.... if you understood the reg ex above...

Now my question is, how can I assign the Words in between these tags into a variable?

I've seen people using $1, $2, etc etc to do something like this, but I haven't worked out how. Please help... I thought about using Preg_Split(), but it would obviously be too long winded... Is there a fast way to access this "string".

View Replies !
Preg_split Problem
I am trying to cut a string into substrings. The string at hand looks
something like this:

$data='one|two|three|four
five|six|seven|eight' //observe the chr(10) in
the middle

I would like to have this split two times. Once to give me the two
'sentences' 'one|two|three|four' and 'five|six|seven|eight'. Then, each of
these sentences would be split into their repective words. Initially I
thought it would be simple:

$sentence=preg_split("
",$data); //should give me an array $sentence
$word=preg_split("|",$sentence[0]); //should give me an array $word

Unfortunately this doesn't work and now I am caught up in a new world of
'regular expression functions' that doesn't seem to make any sense.

View Replies !
Preg_split On Spaces
I'm trying to preg_split an HTML text string $text_thats_too_long on the spaces in order to shorten it to a predefined $word_limit, then recombine the split array using implode(). The goal is to truncate the text, but only on word boundaries. 'Til now I had been using something like this: PHP Code:

$truncated_text = implode(' ', array_slice(preg_split('/s+/', $text_thats_too_long), 0, $word_limit)).'...'

The problem with this is that if $text_thats_too_long contains a hyperlink anchor tag (or any HTML tag with a space in it), the preg_split will operate on the space inside the tag, which is undesirable as it leaves poorly formed HTML: unclosed tags may result.
Is there some other regular expression I can use to ensure I won't be preg_splitting on spaces within tags, or is this impossible to accomplish with a regular expression?

View Replies !
Preg_split() String Trouble
I had a similar topic in the mysql area but this is more a php problem now. When someone enters text into a form I have it querying mysql. Here is my php code PHP Code:

View Replies !
Regular Expression, (preg_split Etc...), Some Help Please.
Consider the string

&#391;,2,3', I can split it using, preg_split("/,/", &#391;,2,3') and i correctly
get [0]=1, [1]=2,[2]=3.

Now if i have

&#391;,"2,3"' i could split it using preg_split("/(?<!"),/d", &#391;,"2,3"') and i
correctly get [0]=1, [1]="2,3".

But it clearly does not work in some more advanced cases, for example

&#391;," 2 , 3"' or &#391;,"2 , 3 "' mainly because the /d is no longer useful.

So how can i search for a regular expression that is *not within*
apostrophes?

I think i might have to write my own split function especially if i have an
extreme case like, &#391;," 2 , " 3"', (note the escape apostrophe).

View Replies !
Order Of Expression In Preg_split
Using PHP 4.3.11

The line: $strDate = preg_split('/[./-]/', $my_date);
works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
mm-dd-yyyy
but the line: $strDate = preg_split('/[/-.]/', $my_date);
doesn't work.

Why does the order of the items make a difference?

View Replies !
Problem With Regex In Preg_split
I do not understand with this regex doesn't work in PHP and yes in Perl PHP Code:

View Replies !
Preg_split/preg_match_all: String -> Paragraph
I want to use preg_match_all to find the location of a string in a series of paragraphs, case does NOT matter.

What I want to happen is after it finds the string it captures the entire paragraph. Each paragraph is returned as a separate result. I tried doing something similar with preg_split, but I ended up with extra paragraphs and data. Code:

View Replies !
Preg_split - Field Is Seperated By Comma
I have a text file which each field is seperated by comma. And each field can contain either numeric character or non-numeric character(which is
surrounded by a pair of double quotes).

But my problem is: if I seperate the fields using comma, then the address field will be seperated into 2 array elements array, since my address field itself contains comma. Code:

View Replies !
Preg_split: Comman And Semi-colon?
I'm trying to split a string by comma and semi-colon. Currently I do it like this...

$str = "mail@example.com, mail1@example.com; mail2@example.com;mail3@example.com,";

$mails = preg_split("/;/", $str);

foreach ($mails as $mail){
    
    $temp_mail =  preg_split("/,/", $mail);
    if($temp_mail){
        foreach ($temp_mail as $temp_m){
            echo $temp_m . "<br>";    
        }
    } else {
        echo $mail;    
    }
}

It works, but is obviously not elegant at all. Is there a way to tell preg_split to split either by comma OR semi-colon? I've played around but haven't figured out how.

View Replies !
Preg_split / Preg_match Test For URI Query Substring?
While I've muddled my way through a few regexp endeavors, for the most part they just leave me scratching my head.

I'm trying to test for the string 'list_edit=true' from a uri such as the following: ....

View Replies !
Pattern Required To Split A String Using Preg_split
I am just entering the world of pattern matching in PHP I am finding it very confusing and would like to a ask a couple of questions..

1. Can anyone tell me the pattern required to split a string using preg_split using colons, fullstops or commas as the delimter... Code:

View Replies !
$alines = Preg_split("/=/", $lines);
is there any thing we can write to keep the right txt to the = sign in
the preg_split. from the following lines

DST-NUMBER-IN=0033512877596, DST-NUMBER-OUT=98751#33512877596,
DST-NUMBER-BILL=0033512877596

i only want 0033512877596, 98751#33512877596, 0033512877596

View Replies !
Iterator First Item?
Let's say I have the code:

foreach($data as $row)
{
do something with each $row
}

Is there a way to do something specific to the first item iterated?
Pseudocode:

foreach($data as $row)
{
if first time through iteration do something with $row
else do something which each remaining $row
}

Is this possible? I think I could use a regular 'for' loop, using the
length of the $data array as a guide, and then an 'if..else' structure
to see if it is the first time through the 'for' loop, but I was
looking for a more elegant solution.

View Replies !
Get One Row, One Item From Database
I was trying to grab just one row and one field in that row from MySQL, but couldn't find a way other than: PHP Code:

View Replies !
Trying To Split The Item...
I'm trying to make a search thru my mySQL database, so it any keywords are found then I'm adding the details to the next item in an array that I create. I've tested the array and it is storing the information into the array properly because it echoes out all of the information correctly. My problem is that, at the beginning of each item in the array I have information that tells me what part of the database it was pulled from and the id number and also how many times the a keyword was found in that specific database entry. So you have something like this.. Code:

View Replies !
Get Last Item In URL String
I realize how elementary this is, I apologize. Maybe that's why I can't find the right answer. I've tried everything from EXPLODEing the string to SUBSTR_REPLACE.

Can anyone tell me how to just get the last item in a URL string? Like turn this:

/mydirectory/myimg.jpg

into this:

myimg.jpg

View Replies !
Most Recent Item
I have a table with every post in - which has a column for the time the post was created and a column for the thread that this post is located in. My threads table has a column for which forum this thread is in and a column for whether the thread is a sticky or not.

On the forum display page, I'd like to display every thread that is in that forum, but ordering them so that any Sticky threads show first (ordered by date created), and then the non-sticky threads are displayed after those ordered according to the time of the most recent post within that thread.

View Replies !
Help With Featured Item
if its possible to display a featured item from mysql table.

Table , links (id, item, hits)

How i could i display 5 links which have bigest numbers ? Is this possible ? I only need query sample, not the entire code.

View Replies !
Pulling One Item
I have a MySQL database with info stored in it (speakers at a weekly seminar). I want to display the seminar's speaker info on my webpage every week. I need it to roll over to the next week's speaker every Thursday at 1:00. I have no clue about where to even get started with this. any ideas?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved