logs archiveIRC Archive / Freenode / #php / 2015 / July / 27 / 1
__adrian
so, is that pastebin the "string" you are talking about, or no?
PatoFeo
por example: {area.1} some non HTML TEXT {area.5}
NiLon
instead of preg_split you want preg_match_all. But even more importantly don't make your own template engine :D
__adrian
PatoFeo: so, is that pastebin the "string" you are talking about, or no?
PatoFeo
the string is dinamically. =)
this is a example string only
__adrian
PatoFeo, I understand that. I am looking for an EXAMPLE string that we can use to figure out your question.
the pastebin you provided is HTML markup.
is that what you are actually working with? HTML markup? you said no a moment ago, so I am not sure.
PatoFeo
yes, in the HTML, have some text that i need to extract, and this text, have this format: {view.X} when i can be a number from 1 to 100
__adrian
ok. do not use regex. http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php
note that this answer offers regex as the "least recommended" solution. I would not recommend it *at all*.
elephaant
can you have static variables in php to cache result?
         

__adrian
elephaant sure
elephaant
like in most real programming languages
PatoFeo
__adrian: mmm, i dont need extract only the text from the html tag, i need extract only string's with the structure {view.X}
elephaant
__adrian: I just declare it static and it'll only be initialized the first time?
PatoFeo
the string {view.X} can be into html tag, or not.
__adrian
PatoFeo, maybe I don't follow what you're asking then. the literal string "{view.", followed by one or more digits, follwoed by "}"?
elephaant yes; but before I answer further, can you explain your situation more?
PatoFeo
__adrian: yes
__adrian
PatoFeo, if it is completely unrelated to the HTML, then sure, do preg_match_all.
PatoFeo
__adrian: and you can recommend me any regular expression?
__adrian
the regex would look like "(\{view\.\d+\})"
Ice_Strike
Is it possible the browser to get the feedback from Redis in realtime using ajax long polling rather than websocket?
PatoFeo
__adrian: yes with preg_split run ok :D
elephaant
__adrian: function get_database_date(){ ..database stuff.. return $result;}. I want to "cache" $result. Can do by making it static, right? isset($result) return $result.
__adrian: this is the design we're going to use. Not in my control.
__adrian
elephaant, is this a function, or a method of a class
elephaant
a function
cannot use globals as it's a foundation of functions.
__adrian
are you invoking it from inside an object? or is this procedural code?
elephaant
__adrian: prodedural
__adrian
ok
PatoFeo
__adrian: thanks =)
__adrian
in php, `static` vars are either inside a function or inside a class definition.
         

elephaant
thanks
:)
__adrian
so, you might wrap your function call in another function, which has a static var to cache the results.
like a memoizer (if you're familiar with the term)
elephaant
not familiar, but no analogies needed :P
__adrian
ok
elephaant
so, how else do you do stuff like this?
__adrian
(well, not an analogy; pretty much exactly what it is)
i would use an object, and cache the results in a factory/data accessor class (possibly in a static property).
or even in a cache (memcached, redis, etc.)
depends on the situation
elephaant
aight
sorabji
i don't know of many uses for caching and discarding data in a single request
PatoFeo
__adrian: with the regx and preg_split, only remove the string {view.X}, howto i can extrat to array, only this string?
__adrian
PatoFeo, i did not suggest preg_split.
PatoFeo
__adrian: =)
__adrian
are you trying to split the string, or to get the {view.X} strings?
NiLon
preg_split is totally wrong function there
PatoFeo
__adrian: get the {view.X} string :D
__adrian: but the regex run OK :D
__adrian
elephaant http://hastebin.com/umapofixeg.php
PatoFeo, read my suggestion again.
elephaant
nice __adrian, thanks.
__adrian
sure.
the factory/data accessor solution is similar, just uses objects.
cquilty
Why should I use XPath over simplexml_load_string to parse an RSS/Atom feed?
__adrian
since things like OO are available, putting static vars into functions is generally frowned upon nowadays
;)
PatoFeo
__adrian: yes, i'm finding in this conversation
__adrian: but with preg_match_all, only return int(2)
__adrian
patoFeo, preg_match_all
read how to use it. http://php.net/preg_match_all
sorabji
cquilty: do you mean DOM ?
cquilty
(Or maybe nobody says that, but then I'm a bit confused.)
sorabji: ?
PatoFeo
__adrian: thanks
cquilty
sorabji: Well... The "XPath stuff".
sorabji
cquilty: there's a DOMXpath
cquilty
sorabji: Why should I use that instead of simplexml_load_string?
__adrian
cquilty, are you asking about this recommendation: !+simplexml
php-bot
cquilty, are you asking about this recommendation, DonĀ“t use SimpleXML, SimpleXML is not simple. Use DOM: http://php.net/manual/en/book.dom.php
cquilty
SimpleXML is not simple?
__adrian
not really
biberu
simplexml is lyingxml
cquilty
It appears to spit out an array of data that matches the RSS feed.
But it does say that it needs a "well-formed XML input", so maybe it breaks often? Is that what you refer to?
__adrian
not saying it doesn't work sometimes. :)
PatoFeo
__adrian: run Perfectly. thanks :D :D
__adrian
sure
cquilty
The manual doesn't seem to give any warnings about this, not in the static content or in the user comments.
But I'll believe you. It makes sense.
Plus I'd rather use XPath as I recently discovered how nice it was for something else (HTML parsing).
biberu
cquilty: the interface is a nightmare, it's only advantage is simplicity in some situations but for most of those you sohuld be using xpath anyway, and thus it doesn't really matter. xpath and simplexml aren't comparable/exclusive either, xpath is a query language that simplexml, dom and other libraries can use to extract data from documents
cquilty
However, I've looked for hours and can't find a single example of somebody actually using XPath to parse an RSS feed. They all recommend crappy libraries or use SimpleXML.
__adrian
cquilty http://stackoverflow.com/questions/4803063/whats-the-difference-between-phps-dom-and-simplexml-extensions
it may be fine for what you're doing. but most people here won't recommend it.
biberu
cquilty: the internet is full of misinformation ^^
cquilty
Sounds like I need XPath and note SimpleXML for sure.
biberu: It certainly is.
*not
__adrian
not full of misinformation?
biberu
cquilty: http://at1.php.net/manual/en/simplexmlelement.xpath.php
you don't choose between them, they are different :)
but no, you don't want simplexml, use php.net/dom instead
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 next »