2010-08-04 18 views
5

के भीतर कोई फ़ंक्शन कैसे चलाएं यह एक त्वरित लेकिन सरल प्रश्न है। मैं एक बुरा दिन हो रहा है और ऐसा करने के तरीके पता नहीं है:इको कॉल

मैं क्या करने की जरूरत है इस है ...

मैं यूआरएल में PMD के लिए जाँच कर रहा हूँ यदि ऐसा है तो यह गूंज:

<?php 
     if (isset($_GET['pmd'])) { 
      echo"<div class=\"response\"><p style=\"width:350px; height:200px; vertical-align:middle;\"><strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! Your name will now appear on our virtual wall.<br><br>You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p></div>"; 
     }else { etc... 

मुझे इसमें शामिल करने की आवश्यकता है जैसे कि एक ट्रैकिंग पिक्सेल को फायर कर रहा है।

<img src="url.com?cid=12345&aid=1234&oid=<?php echo mt_rand(); ?>&quantity=1" height="1" width="1" /> 

क्या मैं करना चाहते हैं यह है:

<?php 
     if (isset($_GET['pmd'])) { 
      echo"<div class=\"response\"><p style=\"width:350px; height:200px; vertical-align:middle;\"><strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! Your name will now appear on our virtual wall.<br><br>You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p> 
      <br /> 
      <img src="url.com?cid=12345&aid=1234&oid=<?php echo mt_rand(); ?>&quantity=1" height="1" width="1" /> 
      </div>"; 
     }else { 

क्या मुझे लगता है कि mt_rand() फ़ंक्शन आग को पाने के लिए क्या करना होगा?

धन्यवाद,

मैट इस तरह

+0

आपको यूआरएल में '' का उपयोग करना चाहिए, न कि '&'। – Artefacto

+0

यदि आप स्ट्रिंग में उद्धरणों से बचना नहीं चाहते हैं (इसे पढ़ने में और अधिक कठिन बनाता है), बस '' ' –

उत्तर

11

इसके बजाय आप इस वाक्य इस्तेमाल कर सकते हैं:

<?php if (isset($_GET['pmd'])): ?> 
    <div class="response"><p style="width:350px; height:200px; vertical-align:middle;"><strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! Your name will now appear on our virtual wall.<br><br>You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p> 
     <br /> 
     <img src="url.com?cid=12345&aid=1234&oid=<?php echo mt_rand(); ?>&quantity=1" height="1" width="1" /> 
    </div> 
<?php else: ?> 
    etc 
<?php endif; ?> 
+0

आपके उत्तर के लिए धन्यवाद – TikaL13

3

कुछ:

<?php 
      if (isset($_GET['pmd'])) { 
       echo "<div class=\"response\"><p style=\"width:350px; height:200px; vertical-align:middle;\"><strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! Your name will now appear on our virtual wall.<br><br>You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p> 
       <br /> 
       <img src=\"url.com?cid=12345&aid=1234&oid=".mt_rand()."&quantity=1\" height=\"1\" width=\"1\" /> 
       </div>"; 
      }else { 
+0

के बजाय ''' 'में स्ट्रिंग को संलग्न करें। – Emyr

1

आपका समस्या यह है कि यदि आप किसी अन्य पीएचपी टैग के अंदर एक PHP टैग (<?php) खोल रहे है (आप ?> साथ बंद करने की आवश्यकता पहले।

ऐसा करने का एक तरीका ऐसा कुछ करना है (मैंने पठनीयता के लिए अपना उदाहरण सरलीकृत किया है):

<?php 

echo '<img src="foo.jpg?oid=', mt_rand(), '">'; 

?> 

कुछ बिंदुओं पर विचार करने के लिए:

  • आमतौर पर आप urlencode का उपयोग जब आप एक यूआरएल में पैरामीटर जोड़ लेकिन mt_rand रिटर्न पूर्णांकों इसलिए हम इस मामले में की जरूरत नहीं है।
  • एक गूंज में . के साथ संगतता कॉन्स के बजाय , के साथ इसे echo परिणामी स्ट्रिंग के साथ आमतौर पर उपयोग करना बेहतर होता है। इस तरह, कम स्मृति का उपयोग किया जाता है और कम परिचालन किए जाते हैं (लेकिन यह इस प्रश्न के दायरे से बाहर है)।
1

उसी तरह आप यह किया - खोलने और बंद करने पीएचपी टैग द्वारा

<?php if (isset($_GET['pmd'])) { ?> 
<div class=\"response\"><p style=\"width:350px; height:200px; vertical-align:middle;\"> 
<strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! 
Your name will now appear on our virtual wall.<br><br> 
You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p> 
<br /> 
<img src="url.com?cid=12345&aid=1234&oid=<?php echo mt_rand(); ?>&quantity=1" height="1" width="1" /> 
      </div> 
<?php  }else { ?> 

मत भूलना इन सभी से छुटकारा पाने के बदसूरत slashes

1

आपको गूंज के साथ स्थिर HTML के बड़े ब्लॉक नहीं जोड़ना चाहिए। आज़माएं:

<?php 
     if (isset($_GET['pmd'])) { 
?> 
      <div class="response"><p style="width:350px; height:200px; vertical-align:middle;"> 
      <strong>Thank you for acting as a &quot;watchman on the walls&quot; of Jerusalem! Your name will now appear on our virtual wall.<br><br>You can also catch up on the latest news from Israel by visiting our news feed below.</strong></p> 
      <br /> 
      <img src="url.com?cid=12345&aid=1234&oid=<?php echo mt_rand(); ?>&quantity=1" height="1" width="1" /> 
      </div> 
<?php 
     }else {//... 
     } 
?> 
संबंधित मुद्दे