dongqing344716 2014-11-06 14:44
浏览 35
已采纳

PHP的strstr()等效于JavaScript [关闭]

I wrote this little piece of code for viewing the profile pictures that are set as private. But every time I have to access it, I have to turn Apache on on XAMPP. Also, it is pretty much useless on a computer that doesn't have Apache installed. So I wanted to write it in JavaScript but couldn't find an equivalent for strstr() function.

Could someone please let me know if there's an equivalent or alternative?

The code:

<?php
    //haystack
    $_POST['theaddress'] ='160x160/photo.jpg';

    //return all after the needle '160x160/', inclusive
    $varA = strstr($_POST['theaddress'], '160x160/');

   //build new URL
    $varA = "https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-9"."$varA";

    header("Location: $varA");
?>
  • 写回答

6条回答 默认 最新

  • dswfyq6201 2014-11-06 15:06
    关注

    JavaScript String's indexOf() function should meet all your requests

    Next example does in JavaScript almost same what you wrote in PHP. Keep in mind that you need to be sure that you have a way to pass $_POST['theaddress'] to your this function. (for example use PHP setcookie() function and then read value in JavaScript code

    function reload(fileName) {
        // define server address variable
        var serverAddress = "https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-9";
    
        // get the filename
        var fileName = fileName.indexOf("160x160/");
    
        // set new location based on server address and filename
        location.href = serverAddress + fileName;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突