Note that there are some explanatory texts on larger screens.

plurals
  1. POPerform an exact match with an if statement
    primarykey
    data
    text
    <p>I'm working on setting up a condition on my web page whereby 1 of 2 things may happen;</p> <p>1) The user posts a youtube link by itself, no other text, and that link is turned into an embeded video on the page.</p> <p>2) Any other kind of post is posted as a regular message, skipping everything in the preceding condition.</p> <p>I have some syntax set up that posts embeded video just fine (first condition), posts text and creates clickable hyperlinks just fine (second condition), but fails if someone tries to post a youtube link along with any other text. It fails because the code that controls condition 1 is not specific enough. Both conditions are processed like this;</p> <pre><code>if(strpos($message,"youtube.com/watch?v=")) { $message = '&lt;iframe width="420" height="315" src="' . str_replace('/watch?v=','/embed/',$message) . '"&gt;&lt;/iframe&gt;'; mysqli_query($db_conn,"insert into feed_messages (userid, subject, message) values ('$useridvalue', '$subject', '$message');") or die("".mysql_error()); $messageid = mysqli_query($db_conn,"select last_insert_id();") or die("".mysql_error()); $messageidvaluearray = mysqli_fetch_assoc($messageid); $messageidvalue = implode(" " , $messageidvaluearray); mysqli_query($db_conn,"insert into feed_recipients (messageid, userid) values ('$messageidvalue', '$useridvalue');") or die("".mysql_error()); foreach($_SESSION['recipientlist'] as $recipient) mysqli_query($db_conn,"insert into feed_recipients (messageid, userid) values ('$messageidvalue', '$recipient');"); header('Refresh: 0; URL=mypage.php'); } else { function make_links_clickable($message) { return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&amp;;//=]+)!i', '&lt;a href="$1" target="_blank" STYLE="TEXT-DECORATION: NONE"&gt;&lt;b&gt;$1&lt;/b&gt;&lt;/a&gt;', $message); } $message = make_links_clickable($message); </code></pre> <p>My question is; how can I make the first if statement more strict so that if it only sees the string "youtube.com/watch?v=" alone, then it executes its code block, otherwise if it see anything else accompanying it, then it can be processed by the else statement?</p> <p>Any help is appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload