Solved

split, REG_EMPTY, and jQuery

Posted on 2009-05-16
4
760 Views
Last Modified: 2012-05-07
I have a case where I'm trying to use "jCarosel".  I have setup a database query (which does work) and returns a result set.  The result set is then brought back into a string variable via mysql_fetch_assoc, using "||" as the field separator.

I then instantiate the array I want to use ($images = array(); ).
The very next thing I do is $images = split('||', $StringToReturn2);

To verify that the $StringToReturn2 does in fact contain results I do an "echo $StringToReturn2;" immediately before the array is established.

I get the following error message:
<b>Warning</b>:  split() [<a href='function.split'>function.split</a>]: REG_EMPTY in <b>C:\inetpub\wwwroot\BACE\jcarousel\examples\dynamic_ajax_php_BACEMod.php</b> on line <b>71</b><br />
1<br />

I think this is telling me that the $StringToReturn2 variable is empty, but I'm not sure.  
I need to get this going and I don't understand why the error.

Thanks in Advance

OldHatt45
$StringToReturn2 = "http://sentinel/BACE/";  //Prepend root location to each value returned.

      while ($row_rsBACEstkType2 = mysql_fetch_assoc($rsBACEstkType2)) { 

	    foreach($row_rsBACEstkType2 as $value1) {

		  $StringToReturn2 .= $value1.'||http://sentinel/BACE/';

		  

	    }

      } 

	  echo $StringToReturn2;

	  $images = array();

	  $images = split('||', $StringToReturn2);

Open in new window

0
Comment
Question by:OldHatt45
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
ziffgone earned 250 total points
Comment Utility
Hi Oldhat45,

The problem is the pipe, "|", is an "or" operator in regular expressions.

Try this:

$images = preg_split('/\|\|/', $StringToReturn2);
0
 
LVL 2

Assisted Solution

by:pedro_sland
pedro_sland earned 250 total points
Comment Utility
Use:
$images = explode('||', $StringToReturn2);
it will be faster as it doesn't use regexs
0
 

Author Closing Comment

by:OldHatt45
Comment Utility
Gentlemen
Both solutions worked!  I just need to see which of the 2 I will actually use.  Since I looked at the answers you both gave at the same time, I feel it only fair to split the points.  Hope this is OK with both of you.

Thank You again

OldHatt45
0
 

Author Comment

by:OldHatt45
Comment Utility
Gentlemen and/or Ladies,
Both solutions worked! Both solutions were "simple" and clear and provide me with what I need.  I just need to see which of the 2 I will actually use. Since I looked at the answers you both gave at the same time, I feel it only fair to split the points. Hope this is OK with both of you.

Thank You again

OldHatt45
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Modify PHP Code on the Fly? 8 38
Creating a slider 12 32
Instering to MySQL table 5 15
Cordova Camera plugin fails 2 5
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

771 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

11 Experts available now in Live!

Get 1:1 Help Now