Solved

split, REG_EMPTY, and jQuery

Posted on 2009-05-16
4
771 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

828 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