How to extract text/string out of MySQL SELECT Query Result with PHP QueryPath without getting “extra HTML” that I am getting?

458 views
Skip to first unread message

Contra Mundi

unread,
Mar 1, 2013, 1:09:37 PM3/1/13
to support-...@googlegroups.com
Original question is here: http://stackoverflow.com/questions/15164111/how-to-extract-text-string-out-of-mysql-select-query-result-with-php-querypath-w


I created a small test database which looks like this:

mysql> select * from person;
+-----------+-------------+
| firstName | lastName    |
+-----------+-------------+
| matt      | butcher     |
| emanuel   | garbaciovas |
+-----------+-------------+
2 rows in set (0.00 sec)

And then I wrote a simple QueryPath Script Like this:

<?php

    require 'src/QueryPath/QueryPath.php';
    require 'src/QueryPath/Extension/QPDB.php';



    $input = qp(QueryPath::XHTML_STUB,'body')->dbInit('mysql:host=localhost;dbname=qpdb',array(username=>'my_username',password=>'my_password'))->queryInto('SELECT firstName FROM person WHERE lastName="butcher"')->doneWithQuery()->writeHTML()->find('body')->text();

    print $input;

?>

Now, I need a string[text value] of the query which I get [i.e. I get what I want, which then I use as an input into html text form on the web/excel/csv/etc], but the problem is, when I run this script from command line, I get extra block of HTML code/document generated which I dont need, i.e. output looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> <title>Untitled</title> </head> <body>matt</body> </html> matt

So basically what I want is "matt", which is what I get, but I also get all of this "extra" as u can see which I dont want. Does anyone know how to extract only "matt"?

I obviously I cant extract text straight out of MySQL query, because it is a resource/object so does anyone knows a way/hack around it? QueryPath or No QueryPath is fine [althought QueryPath hack is better!]



TechnoSophos

unread,
Mar 4, 2013, 10:33:10 AM3/4/13
to support-...@googlegroups.com
Instead of using writeHTML(), use html() or xhtml(). Using writeHTML() will try to fix the HTML.

-- 
TechnoSophos
Twitter: @technosophos
Sent with Sparrow

--
You received this message because you are subscribed to the Google Groups "support-querypath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to support-queryp...@googlegroups.com.
To post to this group, send email to support-...@googlegroups.com.
Visit this group at http://groups.google.com/group/support-querypath?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages