Jump to content

interactive

New Members
  • Posts

    4
  • Joined

  • Last visited

interactive's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. -EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT-EDIT- Oke probleem 1 opgelost. Fout zat hem in een hoofdletter In het XML bestand zeg ik <Item> en in mijn PHP zeg ik foreach ($xml->item as $item) { In de XML aangepast van Item naar item. Tevens wordt er binnen WordPress geen gebruik gemaakt van mysqli_real_escape_string. In plaats hiervan wordt $wpdb->prepare() gebruikt. De code wordt dan: foreach ($xml->Item as $item) { $id = $item->id; $name = esc_sql($item->name); $code = esc_sql($item->code); $email = esc_sql($item->email); $jobdescription = esc_sql($item->jobdescription); $salary = esc_sql($item->salary); $myTitle = 'I have no idea'; $sql = $wpdb->prepare("INSERT INTO wajv_employees (id, name, code, email, jobdescription, salary) VALUES ('$id', '$name', '$code', '$email', '$jobdescription', '$salary')", "%" . $myTitle . "%"); mysql_query($sql) or die ("ERROR:"); echo 'SUCCESS<br>'; } Nu worden de velden wel in de database aangemaakt maar zonder content. Tevens ook geen foutmelding
  2. Ik probeer een online gehost .xml bestand in een database te plaatsen. Ik heb inmiddels alle foutmeldingen weg weten te werken (door ze op te lossen :-)) maar heb nu een blanco pagina zonder errors en geen data in mijn database Hier is wat ik tot nu toe heb gedaan. <?php // Turn off all error reporting error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings ...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE error_reporting(E_ALL & ~E_NOTICE); // Report all PHP errors (see changelog) error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); // specify url of xml file $xmlData = file_get_contents(get_bloginfo('template_directory').'/import/external_db.xml'); // read XML data string $xml = simplexml_load_string($xmlData) or die("ERROR: Cannot create SimpleXML object"); // create and execute INSERT queries foreach ($xml->item as $item) { $id = $item->id; $name = mysqli_real_escape_string($item->name); $code = mysqli_real_escape_string($item->code); $email = mysqli_real_escape_string($item->email); $jobdescription = mysqli_real_escape_string($item->jobdescription); $salary = mysqli_real_escape_string($item->salary); $sql = "INSERT INTO wajv_employees (id, name, code, email, jobdescription, salary) VALUES ('$id', '$name', '$code', '$email', '$jobdescription', '$salary')"; mysqli_query($sql) or die ("ERROR:"); } //mysql_close($connection); ?> Dit is de XML: <?xml version="1.0" encoding="utf-8"?> <data> <Item> <field name="name">xxx</field> <field name="code">101</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">102</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">103</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">104</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> </data> Hoop dat iemand mijn fout over het hoofd ziet
  3. Call me stupid but I just don't see it. I used the preg_replace_callback but there is no image show: $content = preg_replace_callback('/<img[^>]+./', function () { preg_match_all("/<img[^>]+src=(?:\"|\')\K(.[^\">]+?)(?=\"|\')/",$content,$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { $search = array('-'.$s1.'x'.$s2.'', '-'.$s3.'x'.$s4.'', '-'.$s5.'x'.$s6.''); $replace = array('', '', ''); $a = $matches[1][$i]; if (strpos($a,'-'.$s1.'x'.$s2.'') !== false) { $w = $s1; $w = $pdf->pixelsToUnits($w); $h = $s2; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '170'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s3.'x'.$s4.'') !== false) { $w = $s3; $w = $pdf->pixelsToUnits($w); $h = $s4; $h = $pdf->pixelsToUnits($h); $l = '217'; $l = $pdf->pixelsToUnits($l); $t = '20'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s5.'x'.$s6.'') !== false) { $w = $s5; $w = $pdf->pixelsToUnits($w); $h = $s6; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '310'; $t = $pdf->pixelsToUnits($t); } $content .= $pdf->Image(str_replace($search,$replace,$matches[1][$i]), $l, $t, $w, $h, 'JPG', '', '', true, 300, '', false, false, 0, false, false, false); } }, $content );
  4. Hi, I'm using TCPDF to create a PDF from a webpage. This works great but I have the following problem: I'm building in WordPress and as you may know WP saves images on different sizes. (e.g. 150x150, 300x300 and 1024x1024) The thing I'm trying to create is that users can download a PDF ready for printing. So High Resolution images. I use a preg_match_all function to match the image source and remove the additional image size from the filename so the original high resolution image is loaded. e.g. image-150x150.jpg will be replaced by image.jpg. So now the original image that has a image size of 6024x6024px and 300 DPI is loaded. Then TCPDF uses a resize function that resizes the image back to 150x150 px but sets the DPI to 300 so it can be printed on a good quality. This all works but now the problem comes: If I do the preg_match_all function the image gets "pulled" from the rest of the content and looses it's position. So my thought to fix this was. Get a preg_replace function and replace the image tag with a function that executes the whole image change like described above. This doesn't work...... So i'm stuck here. Hope anyone can assist me with this. Here is what I have done so far. function execute(){ preg_match_all("/<img[^>]+src=(?:\"|\')\K(.[^\">]+?)(?=\"|\')/",$content,$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { $search = array('-'.$s1.'x'.$s2.'', '-'.$s3.'x'.$s4.'', '-'.$s5.'x'.$s6.''); $replace = array('', '', ''); $a = $matches[1][$i]; if (strpos($a,'-'.$s1.'x'.$s2.'') !== false) { $w = $s1; $w = $pdf->pixelsToUnits($w); $h = $s2; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '170'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s3.'x'.$s4.'') !== false) { $w = $s3; $w = $pdf->pixelsToUnits($w); $h = $s4; $h = $pdf->pixelsToUnits($h); $l = '217'; $l = $pdf->pixelsToUnits($l); $t = '20'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s5.'x'.$s6.'') !== false) { $w = $s5; $w = $pdf->pixelsToUnits($w); $h = $s6; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '310'; $t = $pdf->pixelsToUnits($t); } $content .= $pdf->Image(str_replace($search,$replace,$matches[1][$i]), $l, $t, $w, $h, 'JPG', '', '', true, 300, '', false, false, 0, false, false, false); } }; global $post; $id = $_GET['id']; $content_post = get_post($id);// get the content $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = preg_replace('/<img[^>]+./e',execute(), $content); // replace the image tag with the new image // EXPORT IT ALL $pdf->writeHTML($content, true, false, true, false, '');
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.