Solved

How to search a string in a mysql text field

Posted on 2014-03-07
4
909 Views
Last Modified: 2014-03-07
Hello,

I need to search a string in a mysql text field that could contains newlines chars. Using the standard LIKE operator it does not work because the string searched is different from the text field as it contains newlines.

Here is an example:
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device. Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

the string could not be found because the text field is:

Fineco App. Tutti i servizi, in tutti i device.
Da dove preferite collegarvi?

https://welcome.fineco.it/bancaonline/extra/fineco-app

So I think there should be e method to search removing newline chars.

thank you
0
Comment
Question by:apedic
  • 3
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39912021
Try
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

or
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\r\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

if the text is from Windows.

HTH,
Dan
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39912023
Or
SELECT id FROM fb_posts WHERE REPLACE(message,"\n","") LIKE '%Fineco App. Tutti i servizi, in tutti i device. Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

0
 

Author Comment

by:apedic
ID: 39912074
thank you, works perfectly!
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39912093
Glad I could help!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

22 Experts available now in Live!

Get 1:1 Help Now