Tuesday, 15 January 2013

php - Issue with hyperlinks when pulling Facebook post into web page -


I am using the following script to draw the latest post from my Facebook page.

It does, it was expected, however, if there is a hyperlink in the Facebook post, the link is distorted & amp; no longer works. Try it out if you can use your code - make sure curl is installed.

  & lt ;? Php $ url = "http://www.facebook.com/feeds/page.php? Id = 466171083413035 & format = json"; // duplicate header and fake user agent is sent to the curl function disguise_curl ($ url) {$ curl = curl_init (); // Setup Header - The same header was divided under Firefox version 2.0.0.6 / / because the line was too long $ header [0] = "Accept: text / XML, App / XML, App / XHTML + XML, "; $ Header [0]. = "Text / html; q = 0.9; text / plain; q = 0.8; image / png; * / *; q = 0.5"; $ Header [] = "cache-control: max-age = 0"; $ Header [] = "Connection: keep-alive"; $ Header [] = "keep-alive: 300"; $ Header [] = "accept-charset: ISO-8859-1, UTF-8; Q = 0.7, *; Q = 0.7"; $ Header [] = "accept-language: en-us, n; c = 0.5"; $ Header [] = "Predama:"; // Let the browser keep it blank Curl_setopt ($ curl, CURLOPT_URL, $ url); Curl_setopt ($ curl, CURLOPT_USERAGENT, 'Mozilla'); Curl_setopt ($ curl, CURLOPT_HTTPHEADER, $ header); Curl_setopt ($ curl, CURLOPT_REFERER, ''); Curl_setopt ($ curl, CURLOPT_ENCODING, 'gzip, deflate'); Curl_setopt ($ curl, CURLOPT_AUTOREFERER, true); Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ curl, CURLOPT_TIMEOUT, 10); $ Html = curl_xax ($ curl); // Turn curl order on curl_close ($ curl); // Connection Close $ html; // And finally, return $ html // uses the function and displays the text with the website $ text = disguise_curl ($ url); $ Json_feed_object = json_decode ($ text); $ I = 0; Foreign exchange ($ json_feed_object-> entries as $ entry) {resonant "<< 2> {$ entry-> title} "; $ Published = date ("G: IAFJ, Y", stratotem (entry-> published)); Echo "& lt; small & gt; {$ published} & lt; / small & gt;"; $ Content = preg_replace ("/ & lt; img [^ & gt;] + \ & gt; / i", "", $ entry-> content); Echo "& lt; p style = 'word-wrap: break-word;' & Gt; {$ content} & lt; / p & gt; "; Echo "& lt; hour / & gt;"; $ I ++; If ($ i == 1) {break}}}? & Gt;   

Edit My hyperlink appears in the form of: & lt; A href = "/ l.php? U = http% 3A% 2F% 2Fwww.empireonline Com% 2Fnews% 2Fstory.asp% 3FNID% 3D36903 & amp; amp; amp; amp; amp; A = AxFajetite 9A & amp = 1" target = "_ Blank "rel =" nofollow nofollow "onmouseover =" linkships link link (this, & amp; quot; http: \ / \ / www.empireonline.com / news \ /story.asp NID = 36,903 & amp; quot;) ; "Onclick =" LinkshipsSync LinkSpeck (this, & amp; amp; quot; \ / l.php? U = http \ u00253A \ u00252F \ u00252Fwww.empireonline.com \ u00252News \ u00252Fstory.asp \ u00253FNID \ u00253D36903 & amp; H = = 1 & amp; quot;) of AXFJETIVE 9A & amp; amp; amp; amp; quot;); & gt; Http: //www.empireonline.com/news/story.asp NID = 36,903 & lt; / A & gt; & Lt; Br / & gt; & Lt; Br / & gt; & Lt; A Href = "http://www.facebook.com/photo.php?fbid=597077380322404&amp;set=a583314588365350.145103.466171083413035&amp;type=1&amp;amp;amp;relevant_count=1" id = "" title = "" Target = "" onclick = "" style = "" & gt; & Lt; / A & gt;

Has anyone ever come up on this issue before? Is there a solution?

Many thanks for any indication.

My bad

The string I wanted on any URL Used to add Facebook.

This is my code, if it helps someone else:

$ content = str_replace ('href = "/ l.php', 'href =" Http://www.facebook.com/l.php',$content);

No comments:

Post a Comment