Can someone explain to me how Hash tags get anchors after being posted. I want to work on a similar implementation in php. The logic behind that operation and links will be useful. thanks
$html = preg_replace("/#([a-z0-9_]+)/", '#${1}', htmlspecialchars($tweet_contents));
something like http://www.snipe.net/2009/09/php-twitter-clickable-links/
Related
i hope you may be able to help me out.
I am building a scrape script using simple html dom.
I have a few sites where i need to get the thumbnail path, name of the movie and some other stuffs. I have build me an admin panel where i save in plaintext the methods required to find that stuff based on the matching pattern.
Eg.
$movie_name = $result->children(0)->children(0)->innertext;
This works just like it supposed to work but when i save children(0)->children(0)->innertext in the database and then back into variable, eg,
$variable = "children(0)->children(0)->innertext";
$movie_name = $result->$variable;
it does not work.
I am pretty sure i am going horribly wrong about this, so please give me a hint how i could just save the methods in plaintext and then call them.
It must be stored in plaintext because the dom is frequently changing so i will be able to keep up with it.
Best regards.
You're looking for the PHP eval() function:
$movie_name = $result->eval($variable);
Having said that, be warned that eval is evil.
Instead, I would recommend xpath.
Hope this helps!
Got it, eval() was the answer. Since no user input is going to the eval() its pretty safe in my particular case. Just had to do some escaping and declaring the variable containing the method inside eval();
This piece of code works for me.
$res_mov_url_e = eval("\$res_mov_url = \$result->$movie_url;");
Anyway big thanks guys!
yeah, I know, the title is kind of confusing, but no better title came to my mind.
Here is my problem:
I want to use a link in my application, which would look like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
The problem is that &someparam2 is meant to hang on the second $_GET-Param.
It would be like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Instead, PHP interprets that &someparam2 hangs on the first $_GET-Param.
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Does anyone know a solution for this?
I already tried
localhost/index?jumpto='some_folder/somescript.php?someparam1=1234&someparam2=4321'
but of course that didn't work.
I hope you can understand my problem.
Thank you for your time.
You will need to URL encode your string some_folder/somescript.php?someparam1=1234 so that php will not parse & in the query string as a param separator.
use urlencode("some_folder/somescript.php?someparam1=1234");
I'm using Mediawiki api in order to get content from Wikipedia pages.
I've written a code which generates the next query (for example):
http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&titles=hawaii
Which retrieves only the leading paragraph from the Wikipdia page about Hawaii.
The problem is that as you might notice there are a lot of irrelevant substrings such as:
"[[Molokai|Moloka{{okina}}i]], [[Lanai|Lāna{{okina}}i]], [[Kahoolawe|Kaho{{okina}}olawe]], [[Maui]] and the [[Hawaii (island)|".
All those barckets [[]] are not relevant , and I wonder whether there is an alegant method to pull only 'clean' content from such pages?
Thanks in advance.
You can get a clean HTML text from Wikipedia with this query:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=hawaii
If you want just a plain text, without HTML, try this:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=hawaii&explaintext
please try this:
$relevant = preg_replace('/[[.*?]]/', '', $string);
EDIT: just found this - hope it is helpful
I have a string and within that string are some links of the format
Text
I want to replace that entire section with a different piece of markup
The problem is that while I can get the overall structure of the markup to be replaced; and also the URL, it's not so easy for me to get the "Text". If I knew the entire link then I might do something like.
'str_replace( $each_link , $my_new_markup , $the_original_string );'
and iterate through each link, but I cant because I cant know what $each_link is going to be exactly.
Is there any way to look for something like this? I am thinking it must have something to do with REGEX but I am totally hopeless at it, and I don't even know if that's the right place to start.
[WILDCARD of some kind]
You could look at a class like this, Simple HTML DOM Parser that you can use to cycle through elements searching for a specific inner html or other attribute and then change it.
Code looking something like this
foreach($html->find('a') as $element) {
if ($element->innertext == $needle) {
$element->innertext = $my_new_markup;
}
}
I want to get the value inside a span id or div id. For example from
<span id="lastPrice">29.00</span>
i want to get the 29.00. please help.
If you want to do this through regexp that badly.
$string = "<span id=\"lastPrice\">29.00</span>";
preg_match("/\<span id\=\"lastPrice\"\>([\d.]+?)\<\/span\>/",$string,$match);
print "<pre>"; var_dump($match[1]); print "</pre>";
But there are far more better ways.
Take a look at XPath => PHP - Searching and filtering with XPath
[...] XPath is a darn sight easier than regular expressions for basic usage. That said, it might take a little while to get your head around all the possibilities it opens up to you!
Google will give u plenty of examples and tutorials.