Ok, I've got this link:
https://picasaweb.google.com/110727246651632161982/2042011#
and I want to use it for cooliris, on their website they make it like this:
picasaweb.google.com%2F%3Fuser%3D110727246651632161982%26album%3D2042011
I want users to post the normal picasa link into my website, then the link has to be replaced and pasted into my database. I know how to do that, but how to get from the picasa link to the usable cooliris link?
Example: DECODE
$url = 'picasaweb.google.com%2F%3Fuser%3D110727246651632161982%26album%3D2042011';
echo urldecode($url);
Output
picasaweb.google.com/?user=110727246651632161982&album=2042011
Example: ENCODE
$url = 'picasaweb.google.com/110727246651632161982/2042011#';
echo urlencode($url);
Output
picasaweb.google.com%2F110727246651632161982%2F2042011%23
References:
urldecode()
urlencode()
Related
I was trying to detect affiliate ID from URLs for a website running in PHP.
the URL examples are
I have changed the affiliate ID into real ones.
https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=honor&ppn=something
https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=apple&ppn=something
https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=sony&ppn=something
I want to replace it with affid=sthachilo
These URLs will be saved in database.
So I cant use $_GET["affid"]
when the URL is shown, I just want to replace the affiliate ID.
or I can use it to replace the affiliate ID and save it in the database.
But I dont know how to detect the affid= section and replace whatever is there.
I tried the following code, but it doesnt seems to be working
$url = "https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=sony&ppn=something";
$newurl = preg_replace('/&affid=(\d+)/','&affid=sthachilo',$url);
echo $newurl;
Here is a real URL example with my affiliate ID in it.
https://www.flipkart.com/complan-kesar-badam/p/itmew2cdj5dmthjk?marketplace=FLIPKART&iid=e6c16ab0-c15d-49c2-843e-cf4a5104c53b.MDMETGN5YZZ5MRYG.SEARCH&ppt=browse&lid=LSTMDMETGN5YZZ5MRYGTBFFJO&srno=b_1_1&pid=MDMETGN5YZZ5MRYG&affid=sthachilo&ssid=7bwqga35j40000001588133282410&ppn=browse
atleast I want to remove everything after itmew2cdj5dmthjk
and add affiliate ID at the end.
for example
https://www.flipkart.com/complan-kesar-badam/p/itmew2cdj5dmthjk?affid=sthachilo
Thanks in advance
you can use parse_url to get the url parts and than use parse_str to get the url query
$url = "https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=sony&ppn=something";
// parse url
$parse = parse_url($url);
// parse the query
parse_str($parse['query'], $query);
// replace the affid with your desired value
$query['affid'] = 'samsung';
// rebuild the query
$parse['query'] = http_build_query($query);
// rebuild the final url
$final_url = $parse['scheme'].'://'.$parse['host'].$parse['path'].'?'.$parse['query'];
echo $final_url
// output : https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=samsung&ppn=something
To replace the given affiliate ID with android:
$url = "https://flipkart.com/product-name/product-id?marketplace=FLIPKART&affid=apple&ppn=something";
$newurl = preg_replace('/&affid=(.+)?&/','&affid=android&',$url);
Probably not the best way to do it since it assumes affid is surrounded by & but if you know that will always be the case then this will work.
How do I strip the url of a google news json feed link?
My link looks like this
http%253A%252F%252Fwww.boston.com%252Fbusiness%252Fnews%252F2014%252F12%252F04%252Fnasa-poised-usher-new-era-with-orion-launch%252FGOh9asOZiRJPHbNw60otUK%252Fstory.html
I have used the following code
strip_tags("".$row['url']."");
This does not do anything, I'm guessing this is possible and I am using the wrong php function.
You can use urldecode for this.
$url = "http%253A%252F%252Fwww.boston.com%252Fbusiness%252Fnews%252F2014%252F12%252F04%252Fnasa-poised-usher-new-era-with-orion-launch%252FGOh9asOZiRJPHbNw60otUK%252Fstory.html";
$url = urldecode(urldecode($url));
echo $url; // Will output: http://www.boston.com/business/news/2014/12/04/nasa-poised-usher-new-era-with-orion-launch/GOh9asOZiRJPHbNw60otUK/story.html
I have a string of html
<img alt='' src='http:\/\/1.gravatar.com\/avatar\/9ed48ee692d84679c0aa2509985a4c74?s=96&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&r=G' class='avatar avatar-96 photo' height='96' width='96' \/>
and I need only to extract the url from it.
Similarly I have this json
[{"ID":1,"post_author":"1","post_date":"2014-04-17 16:09:47","post_date_gmt":"2014-04-17 16:09:47","post_content":"Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!\r\n\r\n<iframe id=\"viddler-ce3d9b65\" src=\"\/\/www.viddler.com\/embed\/ce3d9b65\/?f=1&autoplay=0&player=full&secret=53324891&disablebackwardseek=0&disableseek=0&disableforwardseek=0&loop=0&nologo=0&hd=0\" width=\"437\" height=\"288\" frameborder=\"0\" mozallowfullscreen=\"true\" webkitallowfullscreen=\"true\"><\/iframe>\r\n\r\n ","post_title":"Hello world!","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"open","post_password":"","post_name":"hello-world","to_ping":"","pinged":"","post_modified":"2014-05-09 09:35:11","post_modified_gmt":"2014-05-09 09:35:11","post_content_filtered":"","post_parent":0,"guid":"http:\/\/neevo.simple-task.com\/?p=1","menu_order":0,"post_type":"post","post_mime_type":"","comment_count":"2","filter":"raw"}]
and need to extract only the links to the videos in src.
How do I do that?
update:
this resolved the img scr problem
$dom = new DOMDocument();
$dom->loadHTML($ava);
$url = $dom->getElementsByTagName('img')->item(0)->getAttribute('src');
Assuming you're doing this in php, to be able to extract the JSON information you want, you just simple have to decode it into a php array and then pull out the part you need. So for example:
$json = your_json_feed;
$data = json_decode($json);
$video_url_tmp = $data["post_content"];
That will make $video_url_tmp contain:
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!\r\n\r\n<iframe id=\"viddler-ce3d9b65\" src=\"\/\/www.viddler.com\/embed\/ce3d9b65\/?f=1&autoplay=0&player=full&secret=53324891&disablebackwardseek=0&disableseek=0&disableforwardseek=0&loop=0&nologo=0&hd=0\" width=\"437\" height=\"288\" frameborder=\"0\" mozallowfullscreen=\"true\" webkitallowfullscreen=\"true\"><\/iframe>\r\n\r\n
Which is the part of the JSON feed that you want, that has the URL. Then you'll need a RegEx to pull out the section that you need. It might be easier to RegEx "id=\"viddler-ce3d9b65\" part out, and then figure out how viddler creates its links/embeds/whatever and the form it yourself.
Hope this helps you out.
For referencejson_decode:
http://php.net/manual/en/function.json-decode.php
So I've been using this simple method to determine whether or not a URL is from vimeo
if (preg_match("/vimeo/",$url)) {
$getvim = (parse_url($url));
$vimid = str_replace("/", "", $getvim['path']);
}
As you can see this simply determines if the url contains "vimeo" then grabs the video id by grabbing everything after the slash. Works fine if you're actually linking a vimeo video, however utterly messes everything up if the link just contains "vimeo" without actually being a vimeo link.
Does anyone have a better method of doing this? There are tons of YouTube solutions available but finding a good vimeo one has been nearly impossible. Any help with this is appreciated, thank you.
Try this code:
$urls = parse_url($url);
if ($urls['host'] == 'vimeo.com'){
$vimid = ltrim($urls['path'], '/');
if (is_numeric($vimid)) {
// do something with $vimid
}
}
We assume that all video IDs are numerical.
Read the source of the page via file_get_contents($url) and then check if it contains the string <meta property="og:video" content="http://vimeo.com/moogaloop.swf?clip_id=".$vimid." /> If if contains that string, then you know its a valid video.
I already have a function on my page that produces url from curl. I need to use the following string to return short url in text format or "simple" using the shortswitch.com api.
Here Is my code:
<?php
$long_url = urlencode('curPageURL()');
$url = "http://api.shortswitch.com/shorten?apiKey=[apikey]&format=simple&longUrl={$long_url}";
$result = file_get_contents($url);
print_r($result);
?>
I'm attempting to use a function I found for bit.ly to use with shortswitch.com api as shortswitch.com/admin/api.
My problem is that I'm not getting any type of output from the function, no shortened url is being generated.
best regards,
I'll just guess that you're actually trying to call the function curPageURL() and url encode its result instead of url encoding the string "curPageURL()":
$long_url = urlencode(curPageURL());