Solved

split, REG_EMPTY, and jQuery

Posted on 2009-05-16
4
781 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF Turn Look 7 38
Conformation code 4 37
phpmyadmin memory error 55 96
PHP form submit not returning all values from the form 5 17
This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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)

752 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