-1

I used a code to bulk import the envato items, for example the envato items url is like this :

http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226

How to get only the part "2833226" of this URL with PHP?
I use wordpress and have used custom fields to insert envato item links for example a custom field (afflink) with value :

http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226

and this code to call the custom field value in the theme

$afflink = get_post_meta($post->ID, "afflink", false);

How to get only the item number?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • possible duplicate of [How to check for certain values in url](http://stackoverflow.com/questions/17036271/how-to-check-for-certain-values-in-url) – brasofilo Aug 28 '13 at 03:55

4 Answers4

3

Use explode to split using / caracter and then get the last element of array:

<?php

    $url='http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226';

    $y=explode('/',$url);

    $affiliateID = end($y);
?> 
Charaf JRA
  • 8,249
  • 1
  • 34
  • 44
0
$pattern = "/\d+$/";
$input = "http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226";

preg_match($pattern, $input, $matches);

//Your ID
$post_id = $matches[0];
Parfait
  • 1,752
  • 1
  • 11
  • 12
0

Use this :

value = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);
Roy M J
  • 6,926
  • 7
  • 51
  • 78
0
 $url = 'http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226?r=1';
 $urlParts = parse_url($url);
 $path = $urlParts['path'];
 $pathParts = explode('/',$path);
 $item_id = end($pathParts);

The above code will make sure to avoid query string and read only Uri

Abu Musab
  • 96
  • 6