2

The original text is:

;\n}\nvar vars = {\"uid\":\"170785079\",\"vid\":171461352,\"oid\":170785079,\"host\":509202,\"vtag\":\"493bf2f9dd\",\"ltag\":\"l_8f6ca452\",\"vkid\":171461352,\"md_title\":\"6dfdbda80019208839183a713f243a41\",\"md_author\":\"Ayxan Əmiraslanl\",\"author_id\":170785079,\"author_href\":\"\\\/mr.ayxan\",\"hd\":3,\"no_flv\":1,\"hd_def\":-1,\"dbg_on\":0,\"t\":\"\",\"duration\":244,\"angle\":0.000000,\"img_angle\":0.000000,\"repeat\":0,\"show_ads_preroll\":0,\"show_ads_postroll\":0,\"show_ads_promo_preroll\":0,\"show_ads_overlay\":0,\"ads_type\":-1,\"legal_owner\":0,\"eid1\":0,\"slot\":0,\"g\":1,\"a\":18,\"puid34\":0,\"water_mark\":\"\",\"can_rotate\":1,\"hash\":\"19e3bc2d2ae2f2ce34f6fbaefcf93e2d\",\"hash2\":\"246f9680b9b4f835\",\"is_vk\":\"1\",\"is_ext\":\"0\",\"referrer\":\"\",\"c3\":\"\",\"sample_id\":-1,\"cat_id\":13,\"sitezone\":17,\"ads_preview\":0,\"puid4\":0,\"puid5\":14,\"puid6\":86,\"pl_type\":\"other\",\"nolikes\":1,\"lang_add\":\"Add to My Videos\",\"lang_added\":\"Video added to My Videos\",\"lang_share\":\"Share\",\"lang_like\":\"Like\",\"lang_subscribe\":\"Subscribe\",\"lang_subscribed\":\"You have subscribed\",\"lang_volume_on\":\"Unmute\",\"lang_volume_off\":\"Mute\",\"lang_volume\":\"Volume\",\"lang_hdsd\":\"Change Video Quality\",\"lang_quality_auto\":\"Auto\",\"lang_open_popup\":\"Expand\",\"lang_fullscreen\":\"Full Screen\",\"lang_window\":\"Minimize\",\"lang_rotate\":\"Rotate\",\"lang_ads_link\":\"Advertiser's Site\",\"lang_ads\":\"Ads\",\"lang_ads_skip\":\"Skip ad\",\"lang_ads_skip_time\":\"Skip ads in {time} s\",\"lang_report_problem\":\"Report a problem..\",\"lang_replay\":\"Replay\",\"lang_next_cancel\":\"Cancel\",\"video_play_hd\":\"Watch in HD\",\"video_stop_loading\":\"Stop Download\",\"video_player_version\":\"VK Video Player\",\"goto_orig_video\":\"Go to Video\",\"video_get_video_code\":\"Copy video code\",\"video_load_error\":\"The video has not uploaded yet or the server is not available\",\"video_get_current_url\":\"Copy frame link\",\"lang_next\":\"Next video\",\"url240\":\"https:\\\/\\\/cs509202.vk.me\\\/8\\\/u170785079\\\/videos\\\/493bf2f9dd.240.mp4?extra=SatA0TNoxI3a5jCGpYqhL9FIoS9kjnfIqvkVswFVnFDqJToNiAidxUb2ELSSrSEBNGEvU9Fiseuq5uEQSS_-afULYhnmxc6_vvsCA0mWSYbxDux-HA\",\"url360\":\"https:\\\/\\\/cs509202.vk.me\\\/8\\\/u170785079\\\/videos\\\/493bf2f9dd.360.mp4?extra=SatA0TNoxI3a5jCGpYqhL9FIoS9kjnfIqvkVswFVnFDqJToNiAidxUb2ELSSrSEBNGEvU9Fiseuq5uEQSS_-afULYhnmxc6_vvsCA0mWSYbxDux-HA\",\"url480\":\"https:\\\/\\\/cs509209.vk.me\\\/8\\\/u170785079\\\/videos\\\/493bf2f9dd.480.mp4?extra=SatA0TNoxI3a5jCGpYqhL9FIoS9kjnfIqvkVswFVnFDqJToNiAidxUb2ELSSrSEBNGEvU9Fiseuq5uEQSS_-afULYhnmxc6_vvsCA0mWSYbxDux-HA\",\"url720\":\"https:\\\/\\\/cs509209.vk.me\\\/8\\\/u170785079\\\/videos\\\/493bf2f9dd.720.mp4?extra=SatA0TNoxI3a5jCGpYqhL9FIoS9kjnfIqvkVswFVnFDqJToNiAidxUb2ELSSrSEBNGEvU9Fiseuq5uEQSS_-afULYhnmxc6_vvsCA0mWSYbxDux-HA\",\"jpg\":\"https:\\\/\\\/pp.vk.me\\\/c633320\\\/v633320079\\\/10dcc\\\/GDFulD47LS8.jpg\",\"timeline_thumbs\":1,\"timeline_thumbs_jpg\":\"https:\\\/\\\/pp.vk.me\\\/c628028\\\/v628028079\\\/363df\\\/FVHRrSkD6HM.jpg,https:\\\/\\\/pp.vk.me\\\/c633322\\\/v633322079\\\/f06a\\\/CjskgJb-xxU.jpg\",\"timeline_thumbs_per_row\":10,\"timeline_thumbs_per_image\":100,\"timeline_thumbs_total\":122,\"timeline_thumb_width\":133.000000,\"timeline_thumb_height\":75,\"ip_subm\":1,\"proxy\":\"psv4\",\"https\":1,\"viewer_id\":170785079,\"nologo\":1,\"show_next\":0,\"show_suggestions\":0,\"liked\":0,\"add_hash\":\"0685c16b426a731323\",\"added\":0,\"can_add\":0,\"no_title\":0,\"vsegs_size\":24.000000,\"vsegs_hash\":\"1433edfd589e9d072b\",\"module\":\"direct\",\"playlist_id\":null};\n\nif (!var

how can I get string between var vars and \n\nif (!var

I tried this code:

preg_match('/var vars = (.*?);\n\nif (!var/mis', $get, $result)
1
  • If you're looking for a jsonp_decode function, you can find one here. Commented Jan 25, 2016 at 9:28

3 Answers 3

1

Here is a simple way to get your content without needing to use lookarounds:

preg_match('~var vars = (\{.*?\};)~m', $get, $json_matches);
$json_match = $json_matches[1];
print $json_match;

I am pretty much just matching all of the data between the curly braces from one to the other.

Here is a working demo:

http://ideone.com/ta4sHw

Sign up to request clarification or add additional context in comments.

Comments

1

With a positive lookahead and a lazy quantifier (modified according to your comments):

<?php
$file = file_get_contents("http://shopnow.az/text.txt");
$regex = '~var vars = ({(.*?)(?=};)};)~';
preg_match_all($regex, $file, $matches);
$code = $matches[1][0];
echo $code;
?>

See a demo on regex101.com. This works, however it is very slow and error-prone. Is there some other way to get the code in question?

4 Comments

returned empy array: ` Array ( [0] => Array ( ) [1] => Array ( ) ) `
this is json between var vars and \n\nif (!var
can you check this? kl1p.com/EWxO the full text is this. on php your code dont works
@DilaraAliyeva: See my updated answer, the code works.
0

Just use lookbehind and lookahead:

preg_match_all('/(?<=var\svars).*(?=\\n\\nif \(!var)/', $get, $matches);
var_dump($matches[0][0]);

Demo

Demo PHP Sandbox:

http://sandbox.onlinephpfunctions.com/code/dd38a3bb4384625da11ffaa64795a4ab7b5fbb17

3 Comments

the full text is here: kl1p.com/EWxO
can you look to this link please? the full text is here: kl1p.com/EWxO
it is different text - it doesn't contain the string in question!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.