[Solved] convert this php code to javascript – strpos, str_replace, substr [closed]


Use the search() method of the string object – it returns the position of the match, or -1 if no match is found

var position = -1, oldFlipBookThumb;
var str="<?php echo $video["thumbs']['master'];?>';
if(str.search("/thumbs_old/" != -1){
    position = str.search(".flv");
}
if(position != -1){
    oldFlipBookThumb = str.replace(str.substring(position, Number(position) + 4), '.flv');
}

I could be mistaken, but it looks to me like you are replacing the string “.flv” with the string “.flv”.

In any case, the substring() method of the string object extracts the characters in a string between “from” and “to”, not including “to” itself. string.substring(from, to)

the replace() method of the string object searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring. string.replace(regexp/substr,newstring)

solved convert this php code to javascript – strpos, str_replace, substr [closed]