Welcome Guest, Not a member yet? Register   Sign In
Active Record not showing the result UTF-8
#1

[eluser]souzadavi[/eluser]
Hello, i´m trying to get this done since yesterday, please with some one know any ideia please let me know!! thanks a lot...

I´m getting information from XML

$rss_file = 'http://psyte.uol.com.br/aspx/rss/rss.aspx?s=1';
$xml = simplexml_load_file($rss_file);

//then I define $title with title from XML, working fine.
$title = $xml->channel->item[$i]->title; // this come with value = Rave 2010

$this->Scraps_model->get_cron_topics_search($title)->topic_title;
//I did this because I want to search records from database with this title

// no results
==============================

the problem is when I search from XML I can´t find any result but if I define the search manually like:

$title = 'Rave 2010';
$this->Scraps_model->get_cron_topics_search($title)->topic_title;

this come with results.
=============================

this getting me crazy!!!!! please let me know with anybody have any ideia... thanks!!!!!
#2

[eluser]laytone[/eluser]
I have had problems like this with xml too.

Maybe you could typecast $title to (string) ???
#3

[eluser]souzadavi[/eluser]
i tried:

$title = (string)$title;

but didn´t work... i lost 3 days with this....
#4

[eluser]laytone[/eluser]
I have had the same problem with XML before, I never did find a way to fix it. I think this is an actual PHP bug.

I ran into the error looking at an xml return from a credit card processor and I ended up just using a different processor that returned a string rather than xml because of it.
#5

[eluser]laytone[/eluser]
I found this on the php.net site:

I had a problem with simplexml reading nodes from an xml file. It always return an SimpleXML-Object but not the text inside the node.

Example:
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Id>123</Id>
</Test>

Reading this xml into a variable called $xml and then doing the following
&lt;?php
$myId = $xml->Id;
?&gt;
Did not return 123 in $myId, but instead I got a SimpleXMLElement Object.

The solution is simple, when you know it. Use explicit string conversion.
&lt;?php
$myId = (string)$xml->Id;
?&gt;
#6

[eluser]laytone[/eluser]
And this..

Addition to QLeap's post:
SimpleXML will return a reference to an object containing the node value and you can't use references in session variables as there is no feasible way to restore a reference to another variable.

This won't work too:
$val=$this->xml->node->attributes()->name;
echo $array[$val]; // will cause a warning because of the wrong index type.

You have to convert/cast to a String first:
echo $array[(string)$val];

This will work as expected, because converting will call the __toString() method. Therefor echo works too:
echo $val; // will display the name

Hell, here is a link Smile.. it appears we are not the first to come across the problem!

http://php.net/manual/en/book.simplexml.php
#7

[eluser]souzadavi[/eluser]
thanks to reply, but i saw this information at php.net before post here...


i tried everything, and didn´t work.

(string)$title;

is it another way to do that? i need get information from XML and save that information in data base, but before that i should check if that information is in DB already.

Is it very strange because i did the method to save the information at database, the only thing i couldn´t get done is check if that information is in DB, with search query.

I was thinking about UTF-8 and ISO, but all of my pages and db are in UTF-8.


thanks again for the replys... let see if we can get this fixed....
#8

[eluser]souzadavi[/eluser]
People.. i got!!! i think.. the solution is in:http://ellislab.com/codeigniter/user-guide/general/styleguide.html#strings

Strings

Always use single quoted strings unless you need variables parsed, and in cases where you do need variables parsed, use braces to prevent greedy token parsing. You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.

INCORRECT:
"My String" // no variable parsing, so no use for double quotes
"My string $foo" // needs braces
'SELECT foo FROM bar WHERE baz = \'bag\'' // ugly

CORRECT:
'My String'
"My string {$foo}"
"SELECT foo FROM bar WHERE baz = 'bag'"


you should use {}. i just used {$title} in active record.



$title = $xml->channel->item[$i]->title;

$this->forum->where("topic_title = '{$title}'");// it should be better, but this way worked
$query=$this->forum->get('mytable')->row();


that´s it... thanks people....




Theme © iAndrew 2016 - Forum software by © MyBB