开发者

Explode in jquery with php

开发者 https://www.devze.com 2022-12-27 15:00 出处:网络
I\'ve got a jquery script, which creates a h3 tag and print a variable called result.tbUrl to it开发者_开发技巧. I\'d like to explode the variable at \"::\" and use the 2nd piece.

I've got a jquery script, which creates a h3 tag and print a variable called result.tbUrl to it开发者_开发技巧. I'd like to explode the variable at "::" and use the 2nd piece.

This is my method.

var link = document.createElement('h3');
link.innerHTML = <?php $link = "result.tbUrl"; $linkpiece = explode("::", $link); echo $pieces[1]; ?>;

Could you tell me please where did i make a mistake?


The first problem is, you're echoing $pieces[1], but exploding your string into $linkpiece which is a different variable.

However, you have a more serious problem: You're setting $link to the string "result.tbUrl". The string doesn't contain the delimiter '::', so exploding it has no effect and $linkpiece will be set to array(0 => 'result.tbUrl'). The line echo $linkpiece[1] will fail regardless, as there is nothing at index 1.

If result.tbUrl is a JavaScript variable, you cannot mix it with server-side PHP this way. You'll have to explode the variable client-side, in JavaScript:

var parts = result.tbUrl.split('::');
link.innerHTML = parts[1];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号