search
HomeBackend DevelopmentPHP Tutorialscript中如何做才能调用 php中的变量,如下所示

script中怎么做才能调用 php中的变量,如下所示:
script中怎么做才能调用 php中的变量,如下所示:

  $strbbb = 'www.163.com';
?>

<script><br />function(){window.location.href="$strbbb";}<br /></script>

本来可以在到163网站的,但是我网址却是 $strbbb , 这个该怎么改? 我不是计算机专业的,对这个不大懂,请高手指教

------解决方案--------------------
没法调用!一个客户端一个服务器端!

但可以
$strbbb = 'www.163.com'; 

echo "<script> <br />function(){window.location.href=\"".$strbbb ."\";} <br /></script> ";

?> 
不知道这个算不算!


------解决方案--------------------
$strbbb = 'www.163.com';
?>

<script><br />var aa="<? echo $strbbb; ?>"; <br />alert(aa); <br /></script>
------解决方案--------------------
$strbbb = 'www.163.com';
?>

<script><br />function(){window.location.href="<? echo $strbbb; ?> ";} <br /></script>
------解决方案--------------------

PHP code
<?php $strbbb   =   'www.163.com'; ?><br><font color="#e78608">------解决方案--------------------</font><br>不知道上面几位的代码都测试过没有!<br>抛开其他的单纯就<br>
JScript code
<script> var a = function(){window.location.href="www.163.com";} a();</script><br><font color="#e78608">------解决方案--------------------</font><br><?php   <br />   $strbbb   =   'www.163.com';  <br>?>  <br><br><script>  <br />function(){window.location.href="<?=$strbbb?>";}  <br /></script>  <br><br><font color="#e78608">------解决方案--------------------</font><br><?php <br />   $strbbb   =   'www.163.com';<br>?><br><br><script><br />window.onload = function(){window.location.href="<?=$strbbb?>";}<br /></script><br><font color="#e78608">------解决方案--------------------</font><br>少了【http://】就跳转到你当前网站的目录【www.163.com】,应修改如下:<br><?php <br />   $strbbb = 'http://www.163.com';<br>?><br><br><script><br />window.onload   =   function(){window.location.href=" <?=$strbbb?> ";}<br /></script><br><font color="#e78608">------解决方案--------------------</font><br>不能如此处理<br>var   location   =   ' <?php print   $strbbb?> ';  <br>if   (location.indexOf('://')===-1){  <br>       location   =   'http://'+location;  <br>}  <br>这样根本不会跳转。<br>改<br><script>  <br />function func(){<br /> window.location.href = '<?php echo $strbbb; ?>';<br />}  <br />func();<br /></script><br>你要想纠正$strbbb可以在<br><?php   <br />$strbbb   =   'http://www.163.com';//也可以是www.163.com  <br>?>  <br>里就进行,何必要用javascript呢?<br><font color="#e78608">------解决方案--------------------</font><br><?php $str="asdfa";?><br><script><br />var str="<?php echo $str;?>";<br /></script><div class="clear">
                 
              
              
        
            </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools