Solved

split, REG_EMPTY, and jQuery

Posted on 2009-05-16
4
768 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
ID: 24402922
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
ID: 24402931
Use:
$images = explode('||', $StringToReturn2);
it will be faster as it doesn't use regexs
0
 

Author Closing Comment

by:OldHatt45
ID: 31582239
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
ID: 24403020
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 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