PHP look for image tag on content and append href to image
Can I look for all image tag in content and add a href="image" before the image? I want the image to open on click.
I have tried to get content using preg_match
to append href before it. Below is my code:
preg_match_all('/<img(.*)+>/i',$content, $result);
foreach($result[0] as $k => $v){
//still thinking about the append
}
See also questions close to this topic
-
How do I submit form without page reload taking into consideration the php script?
So basically I have to work on this loan calculator loancalc.000webhostapp.com
I have looked at other pages on this site "how to submit form without page reload?" but this isn't completely relevant to what i'm working on. So far i've added this into the jquery part of the page...
jQuery('qis-register').on('submit', 'input', function(){ event.preventDefault(); var name = $("input#yourname").val(); var email = $("input#youremail").val(); if (name == ""){ $("input#yourname").focus; return false; } else{ } if (email == ""){ $("input#youremail").focus; return false; } });
But i'm told there is also two other scripts that I need to work with, I'm not really too experienced with php so not sure what's going on, the two php scripts I have to work with are called quick-interest-slider.php and register.php,
//qis_verify_application in register.php function qis_verify_application(&$values, &$errors) { $application = qis_get_stored_application(); $register = qis_get_stored_application_messages(); $arr = array_map('array_shift', $application); foreach ($arr as $key => $value) { if ($application[$key]['type'] == 'multi') { $d = explode(",",$application[$key]['options']); foreach ($d as $item) { $values[$key] .= $values[$key.$item]; } } if ($application[$key]['required'] == 'checked' && $register['use'.$application[$key]['section']] && (empty($values[$key]) || $values[$key] == 'Select...')) $errors[$key] = 'error'; } $filenames = array('identityproof','addressproof'); foreach($filenames as $item) { $tmp_name = $_FILES[$item]['tmp_name']; $name = $_FILES[$item]['name']; $size = $_FILES[$item]['size']; if (file_exists($tmp_name)) { if ($size > $register['attach_size']) $errors['attach'.$item] = $register['attach_error_size']; $ext = strtolower(substr(strrchr($name,'.'),1)); if (strpos($register['attach_type'],$ext) === false) $errors['attach'.$item] = $register['attach_error_type']; } } return (count($errors) == 0); } //qis_process_application in register.php function qis_process_application($values) { global $post; $content=''; $register = qis_get_stored_register ('default'); $applicationmessages = qis_get_stored_application_messages(); $settings = qis_get_stored_settings(); $auto = qis_get_stored_autoresponder(); $application = qis_get_stored_application(); $message = get_option('qis_messages'); $arr = array_map('array_shift', $application); if ($message) { $count = count($message); for($i = 0; $i <= $count; $i++) { if ($message[$i]['reference'] == $values['reference']) { $values['complete'] = 'Completed'; $message[$i] = $values; update_option('qis_messages',$message); } } } $filenames = array('identityproof','addressproof'); $attachments = array(); if ( ! function_exists( 'wp_handle_upload' ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } add_filter( 'upload_dir', 'qis_upload_dir' ); $dir = (realpath(WP_CONTENT_DIR . '/uploads/qis/') ? '/uploads/qis/' : '/uploads/'); foreach($filenames as $item) { $filename = $_FILES[$item]['tmp_name']; if (file_exists($filename)) { $name = $values['reference'].'-'.$_FILES[$item]['name']; $name = trim(preg_replace('/[^A-Za-z0-9. ]/', '', $name)); $name = str_replace(' ','-',$name); $_FILES[$item]['name'] = $name; $uploadedfile = $_FILES[$item]; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); array_push($attachments , WP_CONTENT_DIR .$dir.$name); } } remove_filter( 'upload_dir', 'qis_upload_dir' ); $content = qis_build_complete_message($values,$application,$arr,$register); qis_send_full_notification ($register,$values,$content,true,$attachments); qis_send_full_confirmation ($auto,$values,$content,$register); }
function qis_loop in quick-interest-slider.php
function qis_loop($atts) { $qppkey = get_option('qpp_key'); if (!$qppkey['authorised']) { $atts['formheader'] = $atts['loanlabel'] = $atts['termlabel'] = $atts['application'] = $atts['applynow'] = $atts['interestslider'] = $atts['intereselector']= $atts['usecurrencies'] = $atts['usefx'] = $atts['usedownpayment'] = false; if ($atts['interesttype'] == 'amortization' || $atts['interesttype'] == 'amortisation') $atts['interesttype'] = 'compound'; } global $post; // Apply Now Button if (!empty($_POST['qisapply'])) { $settings = qis_get_stored_settings(); $formvalues = $_POST; $url = $settings['applynowaction']; if ($settings['applynowquery']) $url = $url.'?amount='.$_POST['loan-amount'].'&period='.$_POST['loan-period']; echo "<p>".__('Redirecting....','quick-interest-slider')."</p><meta http-equiv='refresh' content='0;url=$url' />"; die(); // Application Form } elseif (!empty($_POST['qissubmit'])) { $formvalues = $_POST; $formerrors = array(); if (!qis_verify_form($formvalues, $formerrors)) { return qis_display($atts,$formvalues, $formerrors,null); } else { qis_process_form($formvalues); $apply = qis_get_stored_application_messages(); if ($apply['enable'] || $atts['parttwo']) return qis_display_application($formvalues,array(),'checked'); else return qis_display($atts,$formvalues, array(),'checked'); } // Part 2 Application } elseif (!empty($_POST['part2submit'])) { $formvalues = $_POST; $formerrors = array(); if (!qis_verify_application($formvalues, $formerrors)) { return qis_display_application($formvalues, $formerrors,null); } else { qis_process_application($formvalues); return qis_display_result($formvalues); } // Default Display } else { $formname = $atts['formname'] == 'alternate' ? 'alternate' : ''; $settings = qis_get_stored_settings(); $values = qis_get_stored_register($formname); $values['formname'] = $formname; $arr = explode(",",$settings['interestdropdownvalues']); $values['interestdropdown'] = $arr[0]; $digit1 = mt_rand(1,10); $digit2 = mt_rand(1,10); if( $digit2 >= $digit1 ) { $values['thesum'] = "$digit1 + $digit2"; $values['answer'] = $digit1 + $digit2; } else { $values['thesum'] = "$digit1 - $digit2"; $values['answer'] = $digit1 - $digit2; } return qis_display($atts,$values ,array(),null); } }
Do I have to edit any of the php and I also don't know what I have to write considering the php.
-
How to make an upload form which requires rights
So I have a Php function in a form for file upload and I want to force people, that want to upload files, to log in. So if someone clicks on upload, an like in-window-pop-up comes up and he is forced to log himself in, or the upload will be canceled.
How do I do that?
index.html
<!DOCTYPE HTML> <html> <head> <title> File-Upload </title> <link style="text/css" rel="stylesheet" href="design.css"/> </head> <body> <div class="form"> <form action="upload.php" method="post" enctype="multipart/form-data"> <input class="select" type="file" name="datei"><br> <input class="upload" type="submit" value="Hochladen"> </form> </div> </body> </html>
upload.php
<?php $upload_folder = 'uploads/'; $filename = pathinfo($_FILES['datei']['name'], PATHINFO_FILENAME); $extension = strtolower(pathinfo($_FILES['datei']['name'], PATHINFO_EXTENSION)); $allowed_extensions = array('png', 'jpg', 'jpeg', 'gif', 'zip', 'rar', 'txt'); if(!in_array($extension, $allowed_extensions)) { die("Ungültige Dateiendung. Nur png, jpg, jpeg, gif, zip, rar und txt-Dateien sind erlaubt"); } $max_size = 1000*1024; //500 KB if($_FILES['datei']['size'] > $max_size) { die("Bitte keine Dateien größer 1000kb hochladen"); } $new_path = $upload_folder.$filename.'.'.$extension; if(file_exists($new_path)) { $id = 1; do { $new_path = $upload_folder.$filename.'_'.$id.'.'.$extension; $id++; } while(file_exists($new_path)); } move_uploaded_file($_FILES['datei']['tmp_name'], $new_path); echo 'Bild erfolgreich hochgeladen: <a href="'.$new_path.'">'.$new_path.'</a>'; ?>
I'm sorry for the German, but I think you can imagine what that would be in English.
-
How to load websites like netflix in PHP
I want to load Netflix on a website by my server. Like hide.me to avoid proxy blocks etc.
Now the problem is that I cant load it by iframe.
I just need my website to be like a little browser and load the website by the server. So when I open whatsmyip.com it should display the ip of my server not mine.
The problem is that I need to send data aswell so login etc works.
I can't use existing websites because they're tooo slow.
Do you guys know how to do a little browser-website?
-
Preg_match for password validation
I need a pre_match for password validation for following constraints :
8 - 20 characters At least one number At least one uppercase letter No spaces
currently, I am using this
preg_match('/^.*(?=.{6,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).*$/')
but it's not satisfying can anyone please help me related this ???
-
Return matches with preg_match without items with numerical keys
$str = 'foobar: 2008'; preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches); print_r($matches); Array ( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 )
I want $matches to contain only 'name' and 'digit' values without deleting the others by iteration.
Is it any faster way? Can preg_match by default return for me only string-type keys ?
Note: the above preg_match is an example. I would like a solution for any inputs.
-
preg match not taking large letter number combo
Preg match will not accept example: Swbermanoo0292. I also would like to allow quotes but cannot figure how to do so. I have searched but cannot find the answer.
if(!preg_match("/^[a-zA-Z0-9]{0,3}*$/", $newuser2) || !preg_match("/^[a-zA-Z0-9.,()!?:\s]*$/", $description)){ //action code here }
I get error: "PHP Warning: preg_match(): Compilation failed: nothing to repeat at offset 13 in..."
I have got the username now with:
(!preg_match("/^[a-zA-Z0-9]*$/", $newuser2))
But when I try:
(!preg_match("/^[a-zA-Z0-9.,()!?:\"\s]*$/", $description))
the regex tester states/ An unescaped delimiter must be escaped with a
backslash (\)