gdfhghjdfghgfhf Posted July 5, 2017 Share Posted July 5, 2017 i looked everywhere but couldnt find a solution... how do i parse discogs bbcode and convert it to html, or just strip it out ? api is returning band biographys with lot of non-standard bbcode and discogs internal link... how can i parse it to human-readable text ready to be displayed to end user on my website ? i asked in discogs forum and got this answer: If you don't want that specific format, you can include an Accept header in your response with your preferred response type. We currently offer Discogs format (what you've got now), plaintext (URLs and other formatting is just stripped away), and HTML. For more information, see the API docs: https://www.discogs.com/developers/#page:home,header:home-versioning-and-media-types So i tried this but it didn't work: curl_setopt($ch, CURLOPT_HTTPHEADER, array('application/vnd.discogs.v2.html+json')); here's what i have so far $ch = curl_init(); //initialize the session curl_setopt($ch, CURLOPT_USERAGENT, 'APN/1.0 +https://www.anarcho-punk.net'); //Set the User-Agent Identifier curl_setopt($ch, CURLOPT_URL, $discogs_label_apiurl); //Set the URL of the page or file to download. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Ask cURL to return the contents in a variable instead of simply echoing them //curl_setopt($ch, CURLOPT_HTTPHEADER, array('application/vnd.discogs.v2.html+json')); // curl_setopt($ch, CURLOPT_HTTPHEADER, array('ACCEPT' => 'application/vnd.discogs.v2.html+json')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('ACCEPT' => 'text/html')); $output = curl_exec($ch); Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 5, 2017 Share Posted July 5, 2017 Read the PHP manual. It explains exactly how headers are set. You also need to start doing error checks. Right now, you just assume that errors will never occur, which is obviously not the case. Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 5, 2017 Author Share Posted July 5, 2017 Can you elaborate ? Just linking the manual with so many different parameters isn't helping me CURLOPT_HTTPHEADER An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100') So my problem is that i didn't set the content-length ? Or i don't need the "ACCEPT" Part ? Or is it something else ? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 5, 2017 Share Posted July 5, 2017 How about actually reading that line you've quoted? That's the format for headers. It doesn't matter if there's one header, two headers or 500 headers. You need to look at the format. Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 5, 2017 Author Share Posted July 5, 2017 What a waste of time, i came here just to get a link to a manual i've already read, with no other additional informations. This forum is useless, back to Stack Overflow. You can delete my account here. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 5, 2017 Share Posted July 5, 2017 Dude. How hard can it be to read a string which is literally on the screen right in front of you? Content-type: text/plain Let's do it together: C - o - n - t - e - n - t - hyphen - t - y - p - e - colon - t - e - x - t - slash - p - l - a - i - n. Or more general: Header name - colon - header value. Name, colon, value. Name, colon, value. Really simply. Stackoverflow cannot do the reading for you either. In fact, you would have -10 votes and a closed topic by now. Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 6, 2017 Share Posted July 6, 2017 I answer a good number of questions over on SO (top 4% overall at the moment), and lately I have noticed that most PHP questions get closed as "Duplicate" in record time. Often within a minute of the question being asked. Unless it's very clear and complete, you're going to get shutdown, and even if you've got a complete, verifiable question, with working code and example data, you still often get marked as dupe, even if there are subtle or even important distinctions in what your question actually entails. In your case, there are numerous CURL related questions that have already been answered, so if you're expecting detailed hand holding, which is not guaranteed but often happens here, you are unlikely to find it. Your question is missing a key ingredient: The specific url you are requesting. If this is not accessible to the public for test purposes, you can always grab the json body of the response and stick it here or in one of the fiddles around. It seems to me that given the simplicity of the default json response, and the usefulness of json_decode(), you have been steered down the wrong path here, perhaps given your original question. Rather than jump to the conclusion of: "Give me something different" it would be helpful if you had shown us what you got, and explained in detail why you were specifically having problems with it. Just because you ask for text, doesn't mean that the text won't have html tags etc in it. I also question that you ever got bbcode, but again your question is missing a lot of details that would have been helpful and might have gotten you a response you would have found more helpful. 1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 6, 2017 Share Posted July 6, 2017 In case the problem still isn't clear: He's using the wrong format for setting the Accept header, so he doesn't get the response type he asked for. The solution is simply to use the right format. I've pointed him to that information, he has even quoted the exact line from the manual, but for some reason he cannot see what's in front of him. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/vnd.discogs.v2.html+json']); // the right format: header name, colon, header value Ironically, not a single user on his beloved Stackoverflow (where he asked the same question) managed to get that right. So whatever he's looking for, it's not competence. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.