Answers.Body: <p>This is a bug in CiviCRM. I can replicate the issue on my database using v4.7.</p>
  
  <p>Basically what is happening is that if a sort order isn't defined, the $order variable is NULL which throws off the strpos() function and sends the error message which then triggers the "headers already sent" errors.</p>
  
  <p>See this post about why the $order variable was changed: <a href="https://forum.civicrm.org/index.php?topic=36040.0" rel="nofollow noreferrer">https://forum.civicrm.org/index.php?topic=36040.0</a></p>
  
  <p>This post <a href="https://civicrm.stackexchange.com/questions/641/empty-needle-error-when-exporting-from-advanced-search-results#answer-685">&quot;Empty needle&quot; error when exporting from Advanced Search results</a> provides a quick fix by hiding error messages.</p>
  
  <p>I've submitted an issue to CiviCRM: <a href="https://issues.civicrm.org/jira/browse/CRM-19212" rel="nofollow noreferrer">https://issues.civicrm.org/jira/browse/CRM-19212</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-10T18:52:50.807Z
Answers.LastActivityDate: 2016-08-10T18:52:50.807Z
Answers.LastEditDate: 2017-04-13T12:53:13.167Z
Answers.UserDisplayName: danbrellis
Body: <p>I've moved to a new server with a current version of PHP, have updated WordPress to 4.5.2 and updated CiviCRM to 4.7.7. I still get this error when exporting selected records from an Advanced Search:</p>
  
  <p>Warning: strpos(): Empty needle in /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php on line 709</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895
  "Contact ID","Contact Type","Contact Subtype","Do Not Email","Do Not Phone","Do Not Mail","Do Not Sms","Do Not Trade","No Bulk Emails (User Opt Out)","Legal Identifier","External Identifier","Sort Name","Display Name","Nickname","Legal Name","Image Url","Preferred Communication Method","Preferred Language","Preferred Mail Format","Contact Hash","Contact Source","First Name","Middle Name","Last Name","Individual Prefix","Individual Suffix","Formal Title","Communication Style","Job Title","Gender","Birth Date","Deceased","Deceased Date","Household Name","Organization Name","Sic Code","Unique ID (OpenID)","Current Employer ID","Contact is in Trash","Created Date","Modified Date","Addressee","Email Greeting","Postal Greeting","Current Employer","Location Type","Street Address","Street Number","Street Number Suffix","Street Name","Street Unit","Supplemental Address 1","Supplemental Address 2","City","Postal Code Suffix","Postal Code","Latitude","Longitude","Address Name","Master Address Belongs To","County","State","Country","Phone","Phone Extension","Email","On Hold","Use for Bulk Mail","Signature Text","Signature Html","IM Provider","IM Screen Name","OpenID","World Region","Website","Group(s)","Tag(s)","Note(s)","Phone Type","IM Service Provider" </p>
  
  <p>It then lists each of the records selected in the same format...</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T00:14:41.307Z
Comments.Text: I edited out your example person's name and street address in case it was a real person. :)
Comments.UserDisplayName: Allen Hutchison
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T14:03:49.213Z
Comments.Text: This seems to be related to your search terms.  If it worked previously, it's definitely a bug - but hard to figure out unless it can be replicated.  Can you share the search terms?  Can you replicate it on the demo server at demo.civicrm.org?  Please update your question with those details and folks can help!
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-05T14:39:22.010Z
Comments.Text: My search was a Postal Code range and resulted in 221 records. I attempted to export all 221 and get that error. At demo.civicrm.org I was able to do a range that resulted in 4 records and the export worked. The demo site is running 4.7.8 so perhaps there is a fix, but I hadn't attempted to upgrade because my site says it is current. The demo site also "meets or exceeds" the minimum recommendation for PHP whereas mine simply meets the minimum but not the recommended version of PHP. Perhaps therein lies the problem.
Comments.UserDisplayName: Steven Price
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-05T18:17:56.987Z
Comments.Text: I upgraded to 4.7.7 which is available and I get more than the one record following the same error messages, now. In other words, still a problem. Perhaps it is a PHP issue. Thoughts?
Comments.UserDisplayName: Steven Price
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-06T14:55:49.960Z
Comments.Text: And thank you Allen Hutchison for your edit.
Comments.UserDisplayName: Steven Price
Tags: <export>
Title: On CiviCRM 4.7.7 Error Exporting
ThreadText: # On CiviCRM 4.7.7 Error Exporting
  
  (Asked by: username_0 on 2016-05-03)
  
  I've moved to a new server with a current version of PHP, have updated WordPress to 4.5.2 and updated CiviCRM to 4.7.7. I still get this error when exporting selected records from an Advanced Search:
  
  Warning: strpos(): Empty needle in /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php on line 709
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Export/BAO/Export.php:709) in /home/zoweh/public\_html/allied/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 895
  "Contact ID","Contact Type","Contact Subtype","Do Not Email","Do Not Phone","Do Not Mail","Do Not Sms","Do Not Trade","No Bulk Emails (User Opt Out)","Legal Identifier","External Identifier","Sort Name","Display Name","Nickname","Legal Name","Image Url","Preferred Communication Method","Preferred Language","Preferred Mail Format","Contact Hash","Contact Source","First Name","Middle Name","Last Name","Individual Prefix","Individual Suffix","Formal Title","Communication Style","Job Title","Gender","Birth Date","Deceased","Deceased Date","Household Name","Organization Name","Sic Code","Unique ID (OpenID)","Current Employer ID","Contact is in Trash","Created Date","Modified Date","Addressee","Email Greeting","Postal Greeting","Current Employer","Location Type","Street Address","Street Number","Street Number Suffix","Street Name","Street Unit","Supplemental Address 1","Supplemental Address 2","City","Postal Code Suffix","Postal Code","Latitude","Longitude","Address Name","Master Address Belongs To","County","State","Country","Phone","Phone Extension","Email","On Hold","Use for Bulk Mail","Signature Text","Signature Html","IM Provider","IM Screen Name","OpenID","World Region","Website","Group(s)","Tag(s)","Note(s)","Phone Type","IM Service Provider"
  
  It then lists each of the records selected in the same format...
  
  **Tags:** export
  
  > **Comments:**
  > **username_1**: I edited out your example person's name and street address in case it was a real person. :)  
  > **username_2**: This seems to be related to your search terms.  If it worked previously, it's definitely a bug - but hard to figure out unless it can be replicated.  Can you share the search terms?  Can you replicate it on the demo server at demo.civicrm.org?  Please update your question with those details and folks can help!  
  > **username_0**: My search was a Postal Code range and resulted in 221 records. I attempted to export all 221 and get that error. At demo.civicrm.org I was able to do a range that resulted in 4 records and the export worked. The demo site is running 4.7.8 so perhaps there is a fix, but I hadn't attempted to upgrade because my site says it is current. The demo site also "meets or exceeds" the minimum recommendation for PHP whereas mine simply meets the minimum but not the recommended version of PHP. Perhaps therein lies the problem.  
  > **username_0**: I upgraded to 4.7.7 which is available and I get more than the one record following the same error messages, now. In other words, still a problem. Perhaps it is a PHP issue. Thoughts?  
  > **username_0**: And thank you username_1 for your edit.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2016-08-10. Score: 2
  
  This is a bug in CiviCRM. I can replicate the issue on my database using v4.7.
  
  Basically what is happening is that if a sort order isn't defined, the $order variable is NULL which throws off the strpos() function and sends the error message which then triggers the "headers already sent" errors.
  
  See this post about why the $order variable was changed: <https://forum.civicrm.org/index.php?topic=36040.0>
  
  This post ["Empty needle" error when exporting from Advanced Search results](https://civicrm.stackexchange.com/questions/641/empty-needle-error-when-exporting-from-advanced-search-results#answer-685) provides a quick fix by hiding error messages.
  
  I've submitted an issue to CiviCRM: <https://issues.civicrm.org/jira/browse/CRM-19212>
  
  
  ---
  
  